Python - 最大回文子串

版权声明:转载请注明出处 https://blog.csdn.net/qq_42292831/article/details/91044874



穷举法:

def x(s):
    if len(s)<=1 or s==s[::-1]:
        return s
    max_substr = ''
    for i in range(len(s)):
        for j in range(i,len(s)):
            substr = s[i:j+1]
            if (substr == substr[::-1]) and len(substr)>len(max_substr):
                max_substr = substr
    return max_substr

猜你喜欢

转载自blog.csdn.net/qq_42292831/article/details/91044874
今日推荐