题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
s=input() l=[] for i in range(len(s)): for j in range(i+1,len(s)): #s0=s[i:j+1] #print(s0) #if s[i:j+1]==s[i:j+1][::-1]: # 对称字符串,正序=倒序(运行超时) if s[j] == s[i] and s[i+1:j] == s[j-1:i:-1]: #先判断首尾是否一致,首尾一致之后再判断内部字符,较省时间 l.append(len(s[i:j+1])) print(max(l))