题解 | #密码截取#
密码截取
https://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
# 你能帮Catcher找出最长的有效密码串吗?找出最长的对称字串 # ABBA 4 # ABBBA 5 # 12HHHHA 4 #对称的密码 s = input() ls= [] for i in range(len(s)-1): for j in range(len(s)-1,i,-1): if s[i] == s[j] and s[i+1:j] == s[j-1:i:-1]: ls.append(j-i+1) break print(max(ls))