题解 | #密码截取#
密码截取
http://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
def expand(s, i, j):
while i >= 0 and j < len(s) and s[i] == s[j]:
i -= 1
j += 1
return i + 1, j - 1
while True:
try:
s = input()
max_lens = 0
for i in range(len(s)):
l1, r1 = expand(s, i, i)
l2, r2 = expand(s, i, i+1)
if r1 - l1 + 1 > max_lens:
max_lens = r1 - l1 + 1
if r2 - l2 + 1 > max_lens:
max_lens = r2 - l2 + 1
print(max_lens)
except:
break