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)
leetcode python 005的更多相关文章
- Leetcode Python Solution(continue update)
leetcode python solution 1. two sum (easy) Given an array of integers, return indices of the two num ...
- LeetCode python实现题解(持续更新)
目录 LeetCode Python实现算法简介 0001 两数之和 0002 两数相加 0003 无重复字符的最长子串 0004 寻找两个有序数组的中位数 0005 最长回文子串 0006 Z字型变 ...
- [LeetCode][Python]Container With Most Water
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/container-with-most-water/ Given n non-neg ...
- LeetCode Python 位操作 1
Python 位操作: 按位与 &, 按位或 | 体会不到 按位异或 ^ num ^ num = 0 左移 << num << 1 == num * 2**1 右移 & ...
- 【leetcode❤python】Sum Of Two Number
#-*- coding: UTF-8 -*- #既然不能使用加法和减法,那么就用位操作.下面以计算5+4的例子说明如何用位操作实现加法:#1. 用二进制表示两个加数,a=5=0101,b=4=0100 ...
- [Leetcode][Python]56: Merge Intervals
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 56: Merge Intervalshttps://oj.leetcode. ...
- [Leetcode][Python]55: Jump Game
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 55: Jump Gamehttps://leetcode.com/probl ...
- [Leetcode][Python]54: Spiral Matrix
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 54: Spiral Matrixhttps://leetcode.com/p ...
- [Leetcode][Python]53: Maximum Subarray
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com' 53: Maximum Subarrayhttps://leetcode.co ...
随机推荐
- h5游戏引擎有哪些
h5游戏引擎有哪些 一.总结 一句话总结: Layabox Egret Pixi.js Three.js PlayCanvas Cocos2d-js Hilo 1.H5游戏开发语言? Flash_AS ...
- linux文件管理之bash shell
BASH Shell 对文件进行管理 ========================================================创建.复制.删除.移动.查看.编辑.压缩.查找 内 ...
- You Don't Know JS: Async & Performance(第2章,Callbacks)
Chapter 2: Callbacks. Callbacks are by far the most common way that asynchrony in JS programs is exp ...
- A Chess Game POJ - 2425
Let's design a new chess game. There are N positions to hold M chesses in this game. Multiple chesse ...
- Java中遍历实体类(处理MongoDB)
在实际过程中,经常要将实体类进行封装,尤其是处理数据库的过程中:因此,对于遍历实体类能够与数据库中的一行数据对应起来. 我是使用的环境是Spring boot,访问的数据库时MongoDB 实体类遍历 ...
- 『MXNet』第九弹_分类器以及迁移学习DEMO
解压文件命令: with zipfile.ZipFile('../data/kaggle_cifar10/' + fin, 'r') as zin: zin.extractall('../data/k ...
- suse11安装mysql5.7
下载地址http://mirrors.sohu.com/mysql/MySQL-5.7/ 1. wget -c http://mirrors.sohu.com/mysql/MySQL-5.7/ ...
- php调用oracle存储
//todo 调用oracle 存储$config = //数据库配置文件 里面包含 用户密码和host和端口以及dbname $conn = oci_connect($config['usernam ...
- HashTable Queue Stack SortedList BitArray
HashTable 由于是非泛型集合,因此存储进去的都是object类型,不管是键还是值. Hashtable不允许排序 key不允许重复 键不允许为null Queue和Queue<T> ...
- oracle的 表、 procedure、package等对象被锁,处理方法
1.0 oracle中表被锁,处理方法 select t4.object_name, t3.spid, t1.oracle_username, t1.os_user_name from v$pro ...