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