zoukankan      html  css  js  c++  java
  • leetcode python 005

    ##  给定字符串,寻找最长回文子串
    ##  单回文,双回文

    def findh(s):
        ## 单回文
        ld,l=[],len(s)
        if len(s)<3:
            return 'too short'
        for i in range(1,l-1):
            for j in range(1,min(i+1,l-i)):
                if s[i-j]!=s[i+j] and j==1:
                    break
                elif s[i-j]!=s[i+j] and j>1:
                    ld.append(s[i-j+1:i+j])
                    break
        
        ##  双回文
        s='#'+s+'?'
        for i in range(1,l):
            for j in range(1,min(i+1,l-i+1)):
                if s[i-j]!=s[i+j-1] and j==1:
                    break
                elif s[i-j]!=s[i+j-1] and j>1:
                    ld.append(s[i-j+1:i+j-1])
                    break
                
        print(len(ld))
        for i in ld:
            print(i)

    s='ssfuhgshjdsdjhvsp-w qncbaccabbvjjkknkl;pp'
    findh(s)

    ----蚂蚁不在线
  • 相关阅读:
    Chapter 4 持久存储数据对象
    pyhton Chapter3 读文件
    python笔记1
    C#读写txt文件
    机器学习第一讲
    Json对象
    表单加载
    多列树
    Java 基础【11】@注解
    Java 基础【06】复合赋值运算
  • 原文地址:https://www.cnblogs.com/offline-ant/p/9365916.html
Copyright © 2011-2022 走看看