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 @   我不知道取什么名字好  阅读(20)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
· Manus的开源复刻OpenManus初探
点击右上角即可分享
微信分享提示