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 ...
随机推荐
- 3. c的输入输出
putchar与getchar操作输入输出通道 #include <stdio.h> #include <ctype.h> main(){ int c; while((c = ...
- Navicat(连接) -1之SSL 设置
SSL 设置 Secure Sockets Layer(SSL) 是一个通过网际网路传输私人文件的协定.为了安全连接,首先你需要做的是安装 OpenSSL 库和下载数据库源. 注意: 只限于 MySQ ...
- C#学习笔记五: C#3.0Lambda表达式及Linq解析
最早使用到Lambda表达式是因为一个需求:如果一个数组是:int[] s = new int[]{1,3,5,9,14,16,22};例如只想要这个数组中小于15的元素然后重新组装成一个数组或者直接 ...
- Linux使用笔记: 定制core dump文件的文件名
在开发过程中,当一个Linux程序异常退出时,我们可以通过core文件来分析它异常的详细原因.缺省情况下,Linux在程序异常时不产生core文件,要想让程序异常退出时产生core dump文件,需要 ...
- angular.js 的angular.copy 、 angular.extend 、 angular.merge
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- ADO.NET(完整修改和查询、实体类,数据访问类)
一.完整修改和查询 在编写c#语句时需考虑到用户体验,例如在编写修改语句时,需要考虑到输入的内容在数据库中是否能够找到. 中间变量运用. 1.先查 2.执行操作 完整修改语句: bool has = ...
- serv-u设置被动模式注意的问题
1.在“本地服务器”->设置->高级里面把端口范围设置一下: 2.在防火墙的入站规则里设置一下上面的端口范围
- 内网Linux对公网开启SSH
1.首先你得装个Linux,过程就不说了.Linux可以装在Vmware上,但是网络适配器选项选的是桥接模式 2.在linux上安装SSH服务,如果有就自动忽略 3.在路由器上开启端口映射. 这里我用 ...
- JAVA 拆分窗口
//拆分窗口 import java.awt.*; import javax.swing.*; public class Jiemian8 extends JFrame{ JSplitPane cf; ...
- Windows下编译使用Aliyun OSS PHP SDK
摘要: WIN环境下搭建Aliyun OSS PHP SDK编译运行环境.从PHP的安装逐步完成,SDK的编译运行.即使没有任何PHP基础,也能顺利完成. 安装环境:Win7 64 + PHP 5.6 ...