题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
from re import template # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param A string字符串 # @return int整型 # class Solution: def getLongestPalindrome(self , A: str) -> int: # write code here def checks(s): # 判断是否为回文子串 t = True if s[::] == s[::-1] else False return t m = 0 for i in range(len(A)): for j in range(i, len(A)): # 遍历所有子串进行判断 if checks(A[i:j+1]): # 记录最长的回文子串长度 m = max(m, len(A[i:j+1])) return m