最长回文子串
最长回文子串
题目:
代码
class Solution:
def longestPalindrome(self, s: str) -> str:
length = len(s)
alist = []
for i in range(length):
for j in range(i, length):
alist.append(s[i:j + 1])
alist.sort(key=lambda x : len(x))
n = -1
while True:
qqs = alist[n]
if qqs == qqs[::-1]:
return qqs
n -= 1
p = Solution()
print(p.longestPalindrome('babad'))