题解 | #最长回文子串#
最长回文子串
http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
#暴解
def huiwen(lists,left,right): while left < right : if lists[left] != lists[right]: return False left += 1 right -= 1 return True maxlen = 1 begin =0 n = list(input()) for i in range(0,len(n)-1): for j in range(i+1,len(n)): if j - i + 1 > maxlen and huiwen(n, i, j): maxlen = j - i + 1#回文长度 begin = i#回文开始坐标 print(len(n[begin:begin+maxlen]))