classSolution: deflongestPalindrome(self, s: str) -> str: ret = ''
for i inrange(0, len(s)): s1 = self.get_palindrome(s, i, i) s2 = self.get_palindrome(s, i, i+1) iflen(s1) > len(ret): ret = s1 iflen(s2) > len(ret): ret = s2
return ret
defget_palindrome(self, s, left_index, right_index): ret = '' while left_index >= 0and right_index < len(s) and s[left_index] == s[right_index]: ret = s[left_index: right_index + 1] left_index -= 1 right_index += 1