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 ...
随机推荐
- C# STUDY
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...
- EL表达式介绍
EL 全名为Expression Language EL 语法很简单,它最大的特点就是使用上很方便.接下来介绍EL主要的语法结构: ${sessionScope.user.sex} 所有EL都是以${ ...
- Category的使用
1.创建一个objective-c file , 可以选择 category, extension ,protocol, empty 文件.选category 就能建立类别. category机制,它 ...
- EventBroker
Sample publisher Publish an event topic: ? 1 2 3 4 5 6 7 8 9 10 public class Publisher { [EventP ...
- 下载文件的一种简单方法js
我在做的一个项目有一部分要下载附件,可是我们公司用了一个包和网上的用response的解决方法冲突,而网上的js解决方法又用到了ActiveXObj我们经理不让用这个.还好我一个同事很利害用了一个很简 ...
- 按列 sort 排序 Linux 如何查看当前占用CPU或内存最多的K个进程
用法:sort [选项]... [文件]...Write sorted concatenation of all FILE(s) to standard output. 长选项必须用的参数在使用短选项 ...
- HOST ip is not allowed to connect to this MySql server
报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在loc ...
- Asteroids (最小覆盖)
题目很简单,但是需要推到出二分图最大匹配 = 最小覆盖 最小覆盖:证明过程http://blog.sina.com.cn/s/blog_51cea4040100h152.html Descriptio ...
- FAQ: Automatic Statistics Collection (文档 ID 1233203.1)
In this Document Purpose Questions and Answers What kind of statistics do the Automated tasks ...
- VirtualBox 使用
安装: # pacman -S virtualbox 配置: 使用时加载vboxdrv模块:#modprobe vboxdrv (或者设置开机加载:1.建立文件“/etc/modules-load.d ...