题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
''' a='gsdgdaber' print(len(a),a[4:7]) for i in range(len(a)): for j in range(i+1,len(a)): print(type(i),type(j)) string_cut=a[i:j] print(string_cut) ''' while 1: try: string=input() palin_len=[] for i in range(len(string)): for j in range(i+1,len(string)): string_cut=string[i:j+1] for k in range(int(len(string_cut)/2)): if string_cut[k]!=string_cut[-(k+1)]: break else: palin_len.append(len(string_cut)) print(max(palin_len)) except: break