题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
x = input()
lx= len(x)
maxodd = [1]*lx
maxeven= [0]*lx
for i in range(lx):
#奇数回文串
low = i-1
high = i+1
maxodd[0] = 1
while (low>=0 and high<=lx-1) and x[low] == x[high]:
maxodd[i] +=2
low -=1
high +=1
#偶数回文串
low = i
high = i+1
while (low>=0 and high<=lx-1) and x[low] == x[high]:
maxeven[i] +=2
low -=1
high +=1
print(max(max(maxodd),max(maxeven)))
小天才公司福利 1156人发布

