题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
def check(x): #确认是否对称 l = int(len(x)/2) if x[:l] == x[l:][::-1] and len(x)%2==0: return True elif x[:l] == x[(l+1):][::-1] and len(x)%2==1: return True else: return False def cal(x): #计算最大子串长度 result = '' for i in range(len(x)+1): for j in range(0,len(x)-i+1): if check(x[j:(j+i)]) and len(x[j:(j+i)]) > len(result): result = x[j:(j+i)] return result while True: try: x = input() print(len(cal(x))) except: break