Given a string, find the length of the longest substring T that contains at most 2 distinct characters.
For example, Given s = “eceba”,
T is "ece" which its length is 3.
这题的线性解法是维护一个sliding w...
分类:
其他好文 时间:
2015-01-06 07:20:32
阅读次数:
121
题目大意:希望在 k 步之内,将尽可能多的1移到相邻的位置上这里依靠前缀和解决问题我们用pos[i]保存第i个1的位置,这里位置我以1开始用sum[i]保存前 i 个1从 0 点移到当前位置所需的步数每次进行判断能否将 st 号 到 la 号的1移到相邻位置,我们要先清楚,为了使移动步数最少,我们需...
分类:
其他好文 时间:
2015-01-05 00:19:23
阅读次数:
111
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters fo...
分类:
其他好文 时间:
2015-01-05 00:18:13
阅读次数:
147
【题目】
Given an unsorted array of integers, find the length of the longest consecutive elements sequence.
For example,
Given [100, 4, 200, 1, 3, 2],
The longest consecutive elements sequence i...
分类:
其他好文 时间:
2015-01-04 23:07:30
阅读次数:
233
public class Solution { public int lengthOfLongestSubstring(String s) { int maxLen = 0; int maxLenTmp = 0; Map map = new HashMap( s.len...
分类:
其他好文 时间:
2015-01-04 11:03:57
阅读次数:
145
Longest Valid ParenthesesGiven a string containing just the characters'('and')', find the length of the longest valid (well-formed) parentheses substr...
分类:
其他好文 时间:
2015-01-03 22:20:40
阅读次数:
131
Longest Common SubsequenceGiven two strings, find the longest comment subsequence (LCS).Your code should return the length of LCS.样例For "ABCD" and "ED...
分类:
其他好文 时间:
2015-01-03 15:55:06
阅读次数:
177
Longest Palindromic Substring
Question
Solution
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...
分类:
其他好文 时间:
2015-01-03 00:57:31
阅读次数:
272
https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/http://fisherlei.blogspot.com/2012/12/leetcode-longest-substring-without.htmlpublicclassSolution{
publicintlengthOfLongestSubstring(Strings){
if(s==null||s.isEmpty())
return0;/..
分类:
其他好文 时间:
2015-01-02 16:16:01
阅读次数:
119
https://oj.leetcode.com/problems/longest-palindromic-substring/http://fisherlei.blogspot.com/2012/12/leetcode-longest-palindromic-substring.htmlpublicclassSolution{
publicStringlongestPalindrome(Strings){
//SolutionA:
returnlongestPalindrome_Center(s);
}
..
分类:
其他好文 时间:
2015-01-02 16:15:08
阅读次数:
122