题目:

提供一个比较容易想到的解法,主要思路是利用滑动窗口,参考代码如下:
class Solution:
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
s = s
mlen = len(s)
while True:
i = 0
while i + mlen <= len(s):
sl = s[i:i + mlen]
sr = sl[::-1]
if sl == sr:
return sl
i = i + 1
mlen = mlen - 1
if mlen == 0:
return "No solution"
网友评论