5. 最长回文子串

给你一个字符串 s,找到 s 中最长的回文子串

 

s = "abcddcboa"

list1 = list(s)
list2 = list(reversed(list1))



def test(s,max_lengh):
    list1 = list(s)
    list2 = list(reversed(list1))
    if s and list1==list2 and len(s)!=1:
        if len(s) not in max_lengh:
            max_lengh.update({len(s):s})
            # print(max_lengh[max(max_lengh)])
    if s:
        test(s[:-1],max_lengh)
        test(s[1:],max_lengh)


max_lengh = {}
test(s,max_lengh)
print(max_lengh[max(max_lengh)])

 

posted @ 2022-01-31 01:10  我不知道取什么名字好  阅读(19)  评论(0编辑  收藏  举报