题目
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Python
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
long_str=''
longest=0
for i in range(len(s)):
for j in range(len(s),i,-1):
if(j-i<longest):
break
if self.is_palindrome(s[i:j]):
if j-i>longest:
long_str=s[i:j]
longest=j-i
break
return long_str
def is_palindrome(self,s):
reverse_str=''
for i in range((len(s))//2):
if s[i]!=s[-i-1]:
return False
return True