longest palindrome
1class Solution(object):
2 def longestPalindrome(self, s):
3 def helper(l, r):
4 while 0 <= l and r < len(s) and s[l] == s[r]:
5 l, r = l - 1, r + 1
6 return s[l + 1: r]
7
8 res = ""
9 for i in range(len(s)):
10 res = max(helper(i, i), helper(i, i + 1), res, key=len)
11 return res
12
13
14Solution().longestPalindrome("kjhdkfjhkjhaskjdhfakjshdfkjashdfkjhabcdcba")