题解 | 中心拓展法#最长回文子串#
最长回文子串
http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
与密码截取这道题一模一样
def spread(left, right):
ans=0
while left>=0 and right<= n-1 and s[left]==s[right]:
ans =right - left +1
left-=1
right+=1
return ans
while True:
try:
s = input()
n = len(s)
max_ans = 0
for i in range(n):
ans1 = spread(i,i)
ans2 = spread(i,i+1)
max_ans = max(ans1,ans2,max_ans)
print(max_ans)
except:
break