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

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. if标签

    If标签如果php中if语句的作用,if是用于流程控制的. 在ThinkPHP中if标签也是用于流程控制的. If标签的语法格式: <if condition=’条件表达式’> 输出结果1 ...

  2. R语言函数总结(转)

    R语言特征 对大小写敏感 通常,数字,字母,. 和 _都是允许的(在一些国家还包括重音字母).不过,一个命名必须以 . 或者字母开头,并且如果以 . 开头,第二个字符不允许是数字. 基本命令要么是表达 ...

  3. 分享:selenium(一) xpath

    xpath无所不能定位.   https://www.w3.org/TR/xpath/all/#axes 两个神器:firebug.xpath-checker 举例:混合定位 //td[a//fron ...

  4. 雷林鹏分享:jQuery EasyUI 表单 - 过滤下拉数据网格

    jQuery EasyUI 表单 - 过滤下拉数据网格 下拉数据网格(Combogrid)组件和下拉框(Combobox)组件的共同点是,除了都具有下拉面板以外,它们都是基于数据网格(Datagrid ...

  5. mq/mysql/redis/nginx常见服务&工具安装

    单机版 3.1安装工具 3.1.1 安装Maven工具 3.1.1上传安装包 1)root用户创建安装目录如/usr/local /maven:   mkdir -p /usr/local/maven ...

  6. Confluence 6 空间标识

    每一个 Confluence 空间都有一个 空间标识(space key),这个空间标识是简短并且是唯一的,这个标识被用来构建到空间的 URL 中. 当你创建一个站点空间,Confluence 将会为 ...

  7. linux基础3

    vim编辑器 vim 操作命令 在命令模式下操作 pageup 往上翻页(重要指数****) pagedown 往下翻页(重要指数****) H 移动到屏幕首行 gg 移动光标到文档的首行(重要指数* ...

  8. string用scanf读入printf输出(节省时间)

    #include <iostream> #include <stdio.h> #include <string.h> using namespace std; in ...

  9. 基于VMware模拟实现远程主机网络通信

    基于VMware模拟实现远程主机网络通信 目的: 基于VMware软件,模拟实现不同网段的两主机,通过路由器进行通信.两主机host A和host B分别处于VMnet6网络和VMnet7网络,都属于 ...

  10. 微信公众号使用LocalStorage解决返回缓存问题

    在开发微信公众号上应用程序时,遇到了一个普遍的问题,从A页跳转到B页后,再由B页跳转回A页,A要要保持跟跳转前一致,通过LocalStorage可以解决. LocalStorage,很好的解决了返回的 ...