o(n)算法地址:http://blog.163.com/zhaohai_1988/blog/static/2095100852012716105847112/

/* pivot varies when the size of substrig is even or odd
* member function parameter varies according to the size of substring
* complexity O(n*n)
*/ class Solution {
public:
string Palindrome(string s, int a,int b)
{
string tmp;
if(a<||b>=s.size())return tmp;
while(a>=&&b<s.size())
{
if(s[a]!=s[b])break;
a--;
b++;
}
tmp=s.substr(a+,b-a-);
return tmp;
}
string longestPalindrome(string s) {
if(s.size()<=)return s;
int start,end;
string maxp,tmp1,tmp2;
for (int i=;i<s.size();i++)
{ tmp1=Palindrome(s,i,i+);
tmp2=Palindrome(s,i-,i+);
if(tmp1.size()<tmp2.size())tmp1=tmp2;
if(maxp.size()<tmp1.size())maxp=tmp1;
} return maxp;
}
};

Leetcode005 Longest Palindromic Substring的更多相关文章

  1. 最长回文子串-LeetCode 5 Longest Palindromic Substring

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

  2. leetcode--5. Longest Palindromic Substring

    题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...

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

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

  4. No.005:Longest Palindromic Substring

    问题: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...

  5. Leetcode Longest Palindromic Substring

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

  6. 【leedcode】 Longest Palindromic Substring

    Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...

  7. [LeetCode_5] Longest Palindromic Substring

    LeetCode: 5. Longest Palindromic Substring class Solution { public: //动态规划算法 string longestPalindrom ...

  8. 5. Longest Palindromic Substring

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

  9. leetcode-【中等题】5. Longest Palindromic Substring

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

随机推荐

  1. Filter实现全站违法关键词屏蔽

    思路:客户端请求服务器数据,经过Filter过滤(请求放行,响应拦截),服务器向客户端返回数据时,在Filter中修改掉返回数据中违法的部分. 修改服务器的响应需要自定义一个HttpServletRe ...

  2. ADF_ADF Faces系列4_ADF数据可视化组件简介之建立BarChart/Gauge/ExportExcel

    2013-05-01 Created By BaoXinjian

  3. CLR和JIT

    在使用IDE进行编译的时候,这个过程具体的叫法是,使用编译器面向CLR来生成代码.对于不同的开发语言,使用的的编译器也不一样,但是生成的代码都一样. “无论选用哪一个编译器,结果都是一个托管模块.” ...

  4. 外中断之swi软件中断:

    在stm32的标准库的外中断库文件中有void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line);原来一直不知道有什么用,现总结一下: 作用:软件模拟产生中断能 ...

  5. psutil模块安装指南(win与linux)

    1.windows下psutil模块安装: https://pypi.python.org/packages/3.4/p/psutil/ 下载符合版本的软件包下载,然后安装即可. 2.ubuntu下载 ...

  6. 并发工具类(三)控制并发线程数的Semaphore

    原文:http://ifeve.com/concurrency-semaphore/#more-14753 简介 Semaphore(信号量)是用来控制同时访问特定资源的线程数量,它通过协调各个线程, ...

  7. (Delphi) Windows 32 API程序设计目录

    这里所有程序均使用Delphi调用Windows 32 API方式实现,并不是使用VCL已经封装好的类实现的! (一)第一个窗口程序 01 创建第一个窗口.

  8. 线程中的wait() 与 锁的关系

    我们先看一段代码: /** * 计算输出其他线程锁计算的数据 * */ public class ThreadA { public static void main(String[] args) th ...

  9. [Flex] PopUpButton系列 —— 判断下拉列表是否选中

    <?xml version="1.0" encoding="utf-8"?> <!--Flex中如何利用dataDescriptor属性和is ...

  10. shell local

    Shell函数定义的变量默认是global的,其作用域从"函数被调用时执行变量定义的地方"开始,到shell结束 http://blog.chinaunix.net/xmlrpc. ...