1750. Minimum Length of String After Deleting Similar Ends

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1750

class Solution:
    def minimumLength(self, s: str) -> int:
        p1 = 0
        p2 = len(s) - 1

        while p1 < p2 and s[p1] == s[p2]:
            c = s[p1]

            while p1 <= p2 and s[p1] == c:
                p1 += 1
            while p1 <= p2 and s[p2] == c:
                p2 -= 1

        return p2 - p1 + 1