class Solution: def longestPalindrome(self, s): """ :type s: str :rtype: str """ longest_str = str() for i in range(len(s)): lstr = get_around_string(s, i, i) rstr = get_around_string(s, i, i+1) longe_str = lstr if len(lstr) >= len(rstr) else rstr longest_str = longe_str if len(longe_str) >= len(longest_str) else longest_str return longest_str
def get_around_string(s, left, right): while left >= 0 and right < len(s) and s[left] == s[right]: left -= 1 right += 1 left += 1 return s[left: right]