[最大最长]最长回文子串
class Solution:
def longestPalindrome(self, s: str) -> str:
n = len(s)
index = 0
max_len = 1
max_str = s[0]
while index < n:
left = math.floor(index)
right = math.ceil(index)
while left >= 0 and right < n and s[left] == s[right]:
if right - left + 1 > max_len:
max_len = right - left + 1
max_str = s[left:right+1]
left -= 1
right += 1
index += 0.5
return max_str

浙公网安备 33010602011771号