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

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)

leetcode python 005的更多相关文章

  1. Leetcode Python Solution(continue update)

    leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...

  2. LeetCode python实现题解(持续更新)

    目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...

  3. [LeetCode][Python]Container With Most Water

    # -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...

  4. LeetCode Python 位操作 1

    Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...

  5. 【leetcode❤python】Sum Of Two Number

    #-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...

  6. [Leetcode][Python]56: Merge Intervals

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...

  7. [Leetcode][Python]55: Jump Game

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...

  8. [Leetcode][Python]54: Spiral Matrix

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...

  9. [Leetcode][Python]53: Maximum Subarray

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 53: Maximum Subarrayhttps://leetcode.co ...

随机推荐

  1. 单调队列 Monotonic Queue / 单调栈 Monotonic Stack

    2018-11-16 22:45:48 一.单调队列 Monotone Queue 239. Sliding Window Maximum 问题描述: 问题求解: 本题是一个经典的可以使用双端队列或者 ...

  2. InputSream转为String

    public static String convertStreamToString(InputStream is) { /* * To convert the InputStream to Stri ...

  3. kibana的 timelion工具

    时序控件(Timelion)是一款时间序列数据可视化工具,它可以将多种独立的数据源合并呈现到一张视图上. .es函数 index 指明索引    .es(index=nginx-access-log- ...

  4. php正则的使用

    函数 描述 preg_filter 执行一个正则表达式搜索和替换 preg_grep 返回匹配模式的数组条目 preg_last_error 返回最后一个PCRE正则执行产生的错误代码 preg_ma ...

  5. Anya and Cubes CodeForces - 525E (双端搜索)

    大意: 给定$n$元素序列$a$, 可以任选不超过$k$个$a_i$变换为$a_i!$, 求变换后任选若干元素和为S的方案数. 分成两块暴搜, 复杂度$O(3^{\frac{n}{2}})$ #inc ...

  6. python记录_day22 序列化

    序列化是指把内存里的数据类型转换成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘和网络传输时只能接受bytes 一.pickle 把python对象写入到文件中的一种解决方案,但是写入到文件 ...

  7. ajax被cancel问题(事件冒泡)

    发送ajax请求的时候发现ajax请求总是被cancel,但是请求却被执行了,查阅了知识之后,发现问题是:事件冒泡,记录下来,供自己和大家学习借鉴. 1. 前提,发出ajax的请求在form表单中 2 ...

  8. shiro中INI配置

    4.1 根对象SecurityManager 从之前的Shiro架构图可以看出,Shiro是从根对象SecurityManager进行身份验证和授权的:也就是所有操作都是自它开始的,这个对象是线程安全 ...

  9. UI基础六:UI报弹窗确认

    数据检查部分: IF gv_zzzcustmodeno1 <> gv_zzzcustmodeno2 AND gv_plg_name NE 'YES'. lv_title = 'Confir ...

  10. 函数使用二:采购申请BAPI_PR_CREATE

    REPORT YTEST01. ***************************采购申请创建*****************************begin DATA:LV_BANFN TY ...