class Solution:
def longestPalindrome(self, s: str) -> str:
ptmp='' #最长字符串的长度,从空开始找到更长的就加入进去
#从中间往两边走,字符是一样的
for i in range(len(s)):
len1=len(self.getlongest(s,i,i)) #bb形式
if len1>len(ptmp):
ptmp=self.getlongest(s,i,i)
len2=len(self.getlongest(s,i,i+1)) #bb形式
if len2>len(ptmp):
ptmp=self.getlongest(s,i,i+1)
return ptmp
def getlongest(self,s,l,r):
while l>=0 and r<len(s) and s[l]==s[r]:
l-=1
r+=1
return s[l+1:r]