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 ...
随机推荐
- CentOS 6.8 源码安装RabbitMQ
一.安装依赖环境 yum install build-essential openssl openssl-devel unixODBC unixODBC-devel make gcc gcc-c++ ...
- how-to-view-source-of-chrome-extension
https://gist.github.com/paulirish/78d6c1406c901be02c2d Option 1: Command-line download extension as ...
- [jQuery] 通过ajax保存到服务器,成功显示信息.
保存数据到服务器,成功时显示信息. jQuery 代码: $.ajax({ type: "POST", url: "some.php", data: " ...
- 二、idea + git
1.配置git file->setting->git Test 2.配置gitHub 2.1 生成gitHub settings->Developer settings->P ...
- delphi 条形码
Delphi中打印条码的方法 导读: 1 通过菜单”Component”下的”Import ActiveX”将“Microsoft Access Barcode Control 9.0”控件引入.这个 ...
- springboot---->java.lang.IllegalArgumentException
springboot aop编程时,在方法上加入通知的注解,添加织入路径测试,发生报错: java.lang.IllegalArgumentException: Pointcut is not wel ...
- pandas选择单元格,选择行列
首先创建示例df: df = pd.DataFrame(np.arange(16).reshape(4, 4), columns=list('ABCD'), index=list('5678')) d ...
- Java对MongoDB中的数据查询处理
Java语言标准的数据库时MySQL,但是有些时候也会用到MongoDB,这次Boss交代处理MongoDB,所以讲代码以及思路记录下了 摸索的过程,才发现软件的适用还是很重要的啊!!! 我连接的Mo ...
- Leetcode 868. 二进制间距
868. 二进制间距 显示英文描述 我的提交返回竞赛 用户通过次数201 用户尝试次数220 通过次数207 提交次数396 题目难度Easy 给定一个正整数 N,找到并返回 N 的二进制表示中 ...
- UI BOL 练习 get value set attr
" " " " "**********************change list************************* "2 ...