class Solution: def getLongestPalindrome(self, A: str) -> int: # write code here dp = 1 for i in range(0, len(A) - 1): if i>0 and A[i - 1] == A[i + 1]: left_point, right_point = i - 1, i + 1 while ( left_point >= 0 and right_point < len(A) and A[left_point] == A[right_point] ): left_point -= 1 right_point += 1 dp = max(dp, right_point - left_point - 1) if A[i + 1] == A[i]: left_point, right_point = i, i + 1 while ( left_point >= 0 and right_point < len(A) and A[left_point] == A[right_point] ): left_point -= 1 right_point += 1 dp = max(dp, right_point - left_point - 1) return dp
点赞

相关推荐

整顿职场的柯基很威猛:这种不可怕,最可怕的是夹在一帮名校里的二本选手,人家才是最稳的。
点赞 评论 收藏
分享
牛客网
牛客企业服务