题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param A string字符串 # @return int整型 # class Solution: def is_huiwen(self,a:str): count = len(a) for i in range(int(count/2)): if a[i] != a[count-i-1]: return False return True def getLongestPalindrome(self , A: str) -> int: count = len(A) if count <= 1: return count max_value = 1 #tmp = [1 for _ in range(count)] for i in range(1,count): for j in range(0,i-max_value+1): if self.is_huiwen(A[j:i+1]): if len(A[j:i+1]) > max_value: max_value = len(A[j:i+1]) continue return max_value