1750. Minimum Length of String After Deleting Similar Ends
On This Page
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