上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 25 下一页
摘要: 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 is [1, 2, 3, 4]. Return its length: 4.Your algorithm should run in O(n) complexity. The key point is that for each nu.. 阅读全文
posted @ 2013-07-24 22:51 冰点猎手 阅读(192) 评论(0) 推荐(0)
摘要: Write a function to find the longest common prefix string amongst an array of strings. class Solution {public: string longestCommonPrefix(vector &strs) { // Start typing your C/C++ solution below // DO NOT write int main() function string result=""; if(strs.size() == ... 阅读全文
posted @ 2013-07-24 22:01 冰点猎手 阅读(159) 评论(0) 推荐(0)
摘要: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", & 阅读全文
posted @ 2013-07-24 21:47 冰点猎手 阅读(211) 评论(0) 推荐(0)
摘要: Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined as a character sequence consists of non-space characters only.For example,Given s = "Hel 阅读全文
posted @ 2013-07-24 20:33 冰点猎手 阅读(194) 评论(0) 推荐(0)
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal is to reach the last index in the minimum number of jumps.For example:Given array A = [2,3,1,1,4]The minimum. 阅读全文
posted @ 2013-07-24 11:17 冰点猎手 阅读(233) 评论(0) 推荐(0)
摘要: Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine if you are able to reach the last index.For example:A = [2,3,1,1,4], return true.A = [3,2,1,0,4], return fal. 阅读全文
posted @ 2013-07-24 09:20 冰点猎手 阅读(265) 评论(0) 推荐(0)
摘要: Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2.For example,Given:s1 = "aabcc",s2 = "dbbca",When s3 = "aadbbcbcac", return true.When s3 = "aadbbbaccc", return false.方法一: DFS,大数据超时class Solution {public: bool dfs(int i1, int i2, int 阅读全文
posted @ 2013-07-23 23:04 冰点猎手 阅读(257) 评论(0) 推荐(0)
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.分析:罗马数字是由字符I,V,X,L,C,D,M等等表示的,其中I = 1;V = 5;X = 10;L = 50;C = 100;D = 500;M = 1000;经过分析发现,当字符所代表的的数字小于下一个字符所代表的的数字时,其值需要从总的数值里减去;别的情况是把其值累加到总的数值里去。class Solution {public: int romanToInt(strin... 阅读全文
posted @ 2013-07-23 21:51 冰点猎手 阅读(152) 评论(0) 推荐(0)
摘要: Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999. 分析:罗马数字是由字符I,V,X,L,C,D,M等等表示的,其中I = 1;V = 5;X = 10;L = 50;C = 100;D = 500;M = 1000;接下来应该是V开始的重复,但是上面要加一个横线,表示对应数字的1000倍。而且对于某位上(以个位为例),1 – 9,应该是:I,II,III,IV,V,VI,VII,VIII,IX而,对于百位上,100 – 900,应. 阅读全文
posted @ 2013-07-23 21:14 冰点猎手 阅读(223) 评论(0) 推荐(0)
摘要: Implement strStr().Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack. KMP :class Solution {public: void calculatNext(char *pattern) { int i = 0, k = -1; next[0] = -1; while( i = 0 && pattern[i] != pattern[k]) k... 阅读全文
posted @ 2013-07-23 11:05 冰点猎手 阅读(220) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 25 下一页