Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution:
- def longestPalindrome(self, s: str) -> str:
- res = ""
- n = len(s)
- dp = [[False]*n]*n
- for j in range(n):
- for i in range(j+1):
- if i==j:
- dp[j][i] = True
- elif j==i+1:
- dp[j][i] = (s[i] == s[j])
- else:
- dp[j][i] = (dp[j-1][i+1] and s[i]==s[j])
- if len(res) < j-i+1 and dp[j][i]:
- res = s[i:j+1]
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement