Login dark

time:2019-12-11 14:57:00

class Solution:
    def longestPalindrome(self, s: str) -> str:
        ret = ''
        #最长子串的长度
        for maxLength in range(1,len(s)+1)[::-1]:
            #判断该长度的子串是否存在
            for i in range(len(s)):
                stmp = s[i:i+maxLength]
                #长度不够,当前长度不符合要求
                if len(stmp) != maxLength:
                    break
                else:
                    if stmp == stmp[::-1]:
                        ret = stmp
                    else:
                        continue
            if ret != '':
                break
        return ret