题解 | #最长回文子串#
最长回文子串
https://www.nowcoder.com/practice/b4525d1d84934cf280439aeecc36f4af
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param A string字符串 # @return int整型 # class Solution: def getLongestPalindrome(self , A: str) -> int: # write code here n = len(A) ans = 0 for i in range(2 * n - 1): l, r = i // 2, i // 2 + i % 2 while l >= 0 and r < n and A[l] == A[r]: l -= 1 r += 1 ans = max(ans, r - l - 1) return ans