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
点赞

相关推荐

皮格吉:不,有的厂子面试无手撕,可以试试。都是一边学一边面。哪有真正准备好的时候,别放弃
无实习如何秋招上岸
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务