#python3 classSolution: """ @param s: input string @return: a string as the longest palindromic substring """ deflongestPalindrome(self, s): # write your code here for length inrange(len(s),0,-1): for i inrange(len(s) - length + 1): l,r = i,i+length-1 while l < r and s[l] == s[r]: l+=1 r-=1 if l>=r: return s[i:i+length] return""
classSolution: """ @param s: input string @return: a string as the longest palindromic substring """ deflongestPalindrome(self, s): if s isNone: returnNone for length inrange(len(s),0,-1): for i inrange(len(s) - length + 1): if self.is_palindrome(s, i, i + length - 1): return s[i:i + length]
return""
defis_palindrome(self,s,left,right): while left < right and s[left] == s[right]: left += 1 right -= 1 return left >= right