求字符串的最长回文子串。【思路】1.从两边开始向中间发展2.从中间开始向两边发展3.从中间开始的变体,较为复杂,详见http://articles.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html【other code1-...
分类:
其他好文 时间:
2015-05-07 11:45:27
阅读次数:
129
public class Solution { public int lengthOfLongestSubstring(String s) { int max = 0; if (s == null || s.length() == 0...
分类:
其他好文 时间:
2015-05-07 07:36:02
阅读次数:
143
Problem:
Given a string S,
find the longest palindromic substring in S.
You may assume that the maximum length of S is
1000, and there exists one unique longest palindromic substring.
Soluti...
分类:
编程语言 时间:
2015-05-06 17:58:34
阅读次数:
183
时间复杂度为O(N)的算法
在网上看到的很牛逼的算法,不是很理解,这里我就不说了,给链接点击打开链接
时间复杂度为O(N²)的算法-从中间向两边展开
回文字符串显然有个特征是沿着中心那个字符轴对称。比如aha沿着中间的h轴对称,a沿着中间的a轴对称。那么aa呢?沿着中间的空字符''轴对称。
所以对于长度为奇数的回文字符串,它沿着中心字符轴对称,对于长度为偶数的回文字符串,它...
分类:
其他好文 时间:
2015-05-06 17:48:55
阅读次数:
124
题目:Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest...
分类:
其他好文 时间:
2015-05-06 17:07:28
阅读次数:
140
这个题目leetcode上提示用动态规划,但是那样要O(n^2)。我自己想出了一个O(n)的算法,并提交通过。【题目】Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.
For "((...
分类:
编程语言 时间:
2015-05-06 11:00:58
阅读次数:
123
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo...
分类:
其他好文 时间:
2015-05-06 06:53:51
阅读次数:
135
原理参考:http://www.douban.com/note/321468038/public class Solution { public String longestPalindrome(String s) { if((s == null) || (s.length() ...
分类:
其他好文 时间:
2015-05-06 01:09:48
阅读次数:
145
Given a stringS, find the longest palindromic substring inS. You may assume that the maximum length ofSis 1000, and there exists one unique longest pa...
分类:
其他好文 时间:
2015-05-05 23:42:33
阅读次数:
168
Problem:
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without
repeating letters for "abcabcbb" is "abc", which the lengt...
分类:
其他好文 时间:
2015-05-05 21:56:58
阅读次数:
134