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-01-06 23:07:00
阅读次数:
208
题目描述:
Write a function to find the longest common prefix string amongst an array of strings.
代码:
string Solution::longestCommonPrefix(vector &strs)
{
string result = "";
if(strs.size(...
分类:
其他好文 时间:
2015-01-06 12:03:24
阅读次数:
137
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
题意:给出n,求把n写成若干个连续素数之和的方案数。分析:这道题非常类似大白书P48的例21,上面详细讲了如何从一个O(n3)的算法优化到O(n2)再到O(nlogn),最后到O(n)的神一般的优化。首先筛出10000以内的素数,放到一个数组中,然后求出素数的前缀和B。这样第i个素数一直累加到第j个...
分类:
编程语言 时间:
2015-01-06 00:47:52
阅读次数:
187
题目大意:希望在 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