class Solution(object):
def longestPalindrome(self, s):
"""
:type s: str
:rtype: str
"""
lenStr = len(s)
if lenStr <= 0:
return 0
maxLen = 0
tmpLen = 0
tmpRes = ''
for i in range(0,lenStr): #odd numbers
j=0
tmpLen=0
while i-j >= 0 and i+j < lenStr and s[i-j] == s[i+j]:
tmpLen = 2*j +1
j+=1
if tmpLen > maxLen:
maxLen = tmpLen
          #i-j+1 plus one because first: j+=1 then judge s[i-j] == s[i+i]
#so when the while cycle stop, the j is bigger one than the j that make while condition establish
tmpRes = s[i-j+1:i+j]
#even numbers
j=0
tmpLen=0
while i-j>=0 and i+j+1 < lenStr and s[i-j] == s[i+j+1]:
tmpLen = 2*j + 2
j+=1
if tmpLen > maxLen:
maxLen = tmpLen
tmpRes = s[i-j+1:i+j+1]
return tmpRes

leetcode Longest Palindromic Substring python的更多相关文章

  1. [LeetCode] Longest Palindromic Substring 最长回文串

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  2. Leetcode Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  3. [LeetCode] Longest Palindromic Substring(manacher algorithm)

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  4. C++ leetcode Longest Palindromic Substring

    明天就要上课了,再过几天又要见班主任汇报项目进程了,什么都没做的我竟然有一种迷之淡定,大概是想体验一波熬夜修仙的快乐了.不管怎么说,每天还是要水一篇博文,写一个LeetCode的题才圆满. 题目:Gi ...

  5. Leetcode: Longest Palindromic Substring && Summary: Palindrome

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  6. Leetcode5:Longest Palindromic Substring@Python

    Given a string s, find the longest palindromic substring in s. You may assume that the maximum lengt ...

  7. LeetCode:Longest Palindromic Substring 最长回文子串

    题目链接 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...

  8. Leetcode: Longest Palindromic Substring. java

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  9. LeetCode——Longest Palindromic Substring

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

随机推荐

  1. SharePoint 2013 设置自己定义布局页

    在SharePoint中.我们常常须要自己定义登陆页面.错误页面.拒绝訪问等:不知道大家怎样操作,曾经自己常常在原来页面改或者跳转.事实上SharePoint为我们提供了PowerShell命令,来改 ...

  2. Android创建启动画面[转]

    每个Android应用启动之后都会出现一个Splash启动界面,显示产品的LOGO.公司的LOGO或者开发者信息.如果应用程序启动时间比较长,那么启动界面就是一个很好的东西,可以让用户耐心等待这段枯燥 ...

  3. bootstrap-js(六)弹出框

    实例 为任意元素添加一小块浮层,用于存放非主要信息. 弹出框的标题和内容的长度都是零的话将永远不会被显示出来. 初始化 由于性能的原因,工具提示和弹出框的 data 编程接口(data api)是必须 ...

  4. context.drawImage绘制图片

    context.drawImage(img,x,y)  x,y图像起始坐标 context.drawImage(img,x,y,w,h) w,h指定图像的宽度和高度 context.drawImage ...

  5. PHP多线程的实现(PHP多线程类)

    通过WEB服务器来实现PHP多线程功能. 当然,对多线程有深入理解的人都知道通过WEB服务器实现的多线程只能模仿多线程的一些效果,并不是真正意义上的多线程. 但不管怎么样,它还是能满足我们的一些需要的 ...

  6. HTML DOM 属性记录

    将HTML DOM中几个容易常用的属性做下记录,需要的朋友可以参考下.     nodeName.nodeValue 以及 nodeType 包含有关于节点的信息. nodeName 属性含有某个节点 ...

  7. Windows下载安装jmeter

    一.下载 jmeter下载地址: http://jmeter.apache.org/download_jmeter.cgi Binaries-apache-jmeter-3.0.zip 二.安装 1. ...

  8. 关于 实时推送技术--WebSocket的 知识分享

    今天学习了关于WebSocket的知识,觉得挺有用的,在这记录一下,也和大家分享一下!!有兴趣的可以看看哦 WebSocket简介 Web领域的实时推送技术,也被称作Realtime技术.这种技术要达 ...

  9. sql查询数据库表中重复记录方法

    1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 代码如下: select * from people where peopleId in (select peopleId ...

  10. HTML标签CSS属性默认值汇总

    HTML标签CSS属性默认值,在你需要还原默认值的时候比较有用. 以前一直在找这份文档,今天偶然在网上看到了.除了inline和block的定义,主要是要注意body|h1~h6|blockquote ...