题解 | #最长回文子串#
最长回文子串
http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507
def cut(s:str): results = [] # x + 1 表示子字符串长度 for x in range(len(s)): # i 表示偏移量 for i in range(len(s) - x): results.append(s[i:i + x + 1]) return results def ishui(string): """ 判断是否为回文串 """ left = 0 rigth = len(string)-1 while (left < rigth): if (string[left] != string[rigth]): return False left += 1 rigth -= 1 return True while True: try: n_str = input() #n_str = "abcbaaa" res = cut(n_str) #print(res) n_len = [] #?print(res) for ele in res: if ishui(ele) ==True: n_len.append(len(ele)) print(max(n_len)) break except: break 实在人的暴力求解方法,大神的做法做不来