class Solution:
def longestPalindrome(self, s: str) -> str:
if len(s) <= 1:
return s
if len(set(s)) == 1:
return s
l = 0
r = len(s)
rlt = ""
while l < len(s):
if s[l:r] == s[l:r][::-1]:
if (r - l) > len(rlt):
rlt = s[l:r]
r -= 1
if r == l:
l += 1
r = len(s)
return rlt
5,最长回文子串
最新推荐文章于 2024-07-24 18:09:48 发布