leetcode-mid-array-5. Longest Palindromic Substring
mycode 12.51%
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
length = len(s)
if length==0:
return ''
res = s[0]
for i in range(length-1):
for j in range(i+1,length):
if s[j] == s[i]:
temp = s[i:j+1]
if temp == temp[::-1]:
if len(temp) > len(res):
res = temp[:]
return res
参考:
class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
n = len(s)
maxl, start = 0, 0
for i in range(n):
if i - maxl >= 1 and s[i-maxl-1:i+1] == s[i-maxl-1:i+1][::-1]:
start = i - maxl - 1
maxl += 2
continue
if i - maxl >= 0 and s[i-maxl:i+1] == s[i-maxl:i+1][::-1]:
start = i - maxl
maxl += 1
return s[start: start + maxl]
leetcode-mid-array-5. Longest Palindromic Substring的更多相关文章
- leetcode 第五题 Longest Palindromic Substring (java)
Longest Palindromic Substring Given a string S, find the longest palindromic substring in S. You may ...
- leetcode第五题--Longest Palindromic Substring
Problem:Given a string S, find the longest palindromic substring in S. You may assume that the maxim ...
- Leetcode:【DP】Longest Palindromic Substring 解题报告
Longest Palindromic Substring -- HARD 级别 Question SolutionGiven a string S, find the longest palindr ...
- leetcode--5 Longest Palindromic Substring
1. 题目: Given a string S, find the longest palindromic substring in S. You may assume that the maximu ...
- LeetCode(5)Longest Palindromic Substring
题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
- leetcode:Longest Palindromic Substring(求最大的回文字符串)
Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...
- [LeetCode][Python]Longest Palindromic Substring
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- 【LeetCode】Longest Palindromic Substring 解题报告
DP.KMP什么的都太高大上了.自己想了个朴素的遍历方法. [题目] Given a string S, find the longest palindromic substring in S. Yo ...
- Leetcode: Longest Palindromic Substring && Summary: Palindrome
Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
随机推荐
- GmSSL Build with VS2017
使用背景: 最近研究GB35114, 有关于sip协议部分,exosip的已经编译过,由于gb3511中采用的是国密算法,因此这里记录一下GMSSL在windows下的编译过程以及遇到的错误 详细GM ...
- OD消息断点
[文章作者]: icefisher[作者邮箱]: 181712814@qq.com[软件下载]: [软件名称]: echap518.exe(只是供学习的crackme)[加壳方式]: 里面直接有个un ...
- gulp程序怎么跑起来 及 使用中遇到的常见错误
gulp常见问题 问题一:Error: cannot find module 'gulp-concat' #16 解答:需要先npm install,然后执行gulp gulp安装及使用 一.安装no ...
- css厂商前缀
在vue中写css,不要加厂商前缀,vue-cli会在打包时自动生成
- java调用webservice接口 几种方法
webservice的 发布一般都是使用WSDL(web service descriptive language)文件的样式来发布的,在WSDL文件里面,包含这个webservice暴露在外面可供使 ...
- 拼接HTML代码在UIWebVIew中显示
其原理:通过网络请求获得相关的信息,再通过手机端进行拼HTML,然后在WebView进行展示,此处还对文章中的图片增加点击效果,可以保存到相册中:文章的样式已经存在项目中,直接去调用: 1:首先了解两 ...
- mailstats - 显示邮件状态信息
总览 mailstats [-o] [-C cffile] [-f stfile] 描述 mailstats工具显示当前的邮件状态信息. 首先,先显示统计启动时所记录的时间,当然是以ctime(3)所 ...
- Ubuntu系统下Bazel编译Tensorflow环境
编写此文主要为了介绍在Ubuntu16.04上搭建Tensorflow-lite编译环境,涉及目标硬件为Armv7架构,8核Cortex-A7. 1.开发环境介绍: OS:Ubuntu16.04 64 ...
- JavaEE高级-MyBatis学习笔记
一.MyBatis简介 - MyBatis 是支持定制化 SQL.存储过程以及高级映射的优秀的持久层框架. - MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. - My ...
- 高可用4层lvs——keepalived
搭建方式: node01: ipvsadm -C ifconfig eth0:2 down --------------------------------- node01,node04安装keepa ...