摘要: 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)