class Solution(object):
def minimumLength(self, s):
"""
:type s: str
:rtype: int
"""
n = len(s)
ans = 0
p1, p2 = 0, n - 1
while p1 <= p2:
cur_c = s[p1]
if s[p2] != cur_c or p1 == p2:
ans = p2 - p1 + 1
break
while p1 <= p2 and s[p1] == cur_c:
p1 += 1
while p1 <= p2 and s[p2] == cur_c:
p2 -= 1
return ans