Leetcode005 Longest Palindromic Substring
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的更多相关文章
- 最长回文子串-LeetCode 5 Longest Palindromic Substring
题目描述 Given a string S, find the longest palindromic substring in S. You may assume that the maximum ...
- leetcode--5. Longest Palindromic Substring
题目来自 https://leetcode.com/problems/longest-palindromic-substring/ 题目:Given a string S, find the long ...
- [LeetCode] Longest Palindromic Substring 最长回文串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- No.005:Longest Palindromic Substring
问题: Given a string S, find the longest palindromic substring in S. You may assume that the maximum l ...
- Leetcode Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- 【leedcode】 Longest Palindromic Substring
Given a , and there exists one unique longest palindromic substring. https://leetcode.com/problems/l ...
- [LeetCode_5] Longest Palindromic Substring
LeetCode: 5. Longest Palindromic Substring class Solution { public: //动态规划算法 string longestPalindrom ...
- 5. Longest Palindromic Substring
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- leetcode-【中等题】5. Longest Palindromic Substring
题目 Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
随机推荐
- windows7修改双系统启动项名称、先后顺序、等待时间
一.进入BCDEdit.exe 正常启动Windows 7 系统,点击“开始” -> “所有程序” -> “附件”,右击“命令提示符” -> “以管理员身份运行”(需要将操作当前用 ...
- WindowsForm应用程序调用WebService
本文原创,如需转载,请标明源地址,谢谢合作!http://blog.csdn.net/sue_1989/article/details/6597078 本文的编写IDE为VSTS2008和.NET F ...
- socket 发送发送HTTP请求
socket方式: $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); //socket_set_option($socket, SOL_S ...
- [物理学与PDEs]第4章 反应流体力学
[物理学与PDEs]第4章第1节 引言 [物理学与PDEs]第4章第2节 反应流体力学方程组 2.1 粘性热传导反应流体力学方程组 [物理学与PDEs]第4章第2节 反应流体力学方程组 2.2 反应流 ...
- C# 导出 Excel 和相关打印设置
源地址:http://blog.csdn.net/wanmingtom/article/details/6125599 Excel.Application myExcel = new Excel.Ap ...
- Java SE 第十六讲----面向对象特征之继承
1.继承(inheritance):Java是单继承的,意味着一个类只能从另一个类继承(被继承的类叫做父类也叫[基类 baseclass]),继承的类叫做子类,java中的继承使用extends关键字 ...
- (easy)LeetCode 205.Isomorphic Strings (*)
Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the chara ...
- Linux Hugepage ,AMM及 USE_LARGE_PAGES for oracle 11G(转载)
1. Hugepage基本概念 系统进程是通过虚拟地址访问内存,但是CPU必须把它转换成物理内存地址才能真正访问内存.为了提高这个转换效率,CPU会缓存最近的“虚拟内存地址和物理内存地址”的 ...
- win7设置防火墙允许Ping与telnet
Ping: 打开控制面板 >> 系统安全 >> windows防火墙 >> 高级设置 >> 入站规则
- pm剩余要看的内容
1. thermal profiles tuning, customize thermal daemon for different thermal usage model 2.gas gauge d ...