Open Shuai-Lou opened 1 year ago
Longest Palindromic Substring
class Solution: def longestPalindrome(self, s: str) -> str: n = len(s) ans = s[0] if n == 1: return ans for i in range(n-1): for j in range(i+1, n): if s[i] == s[j]: res = s[i:j+1] if res == res[::-1] and len(res) > len(ans): ans = res
return ans