上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 20 下一页
摘要: A classic subroutine of merge sort. Just merge the elements from back to forth. Keep a pointer for the merged position of the element and two other po... 阅读全文
posted @ 2015-07-02 18:11 jianchao-li 阅读(176) 评论(0) 推荐(0) 编辑
摘要: The typical solution to this problem is to use Dynamic Programming. The state dp[i] represents whether s[0..i - 1] can be broken into words in wordDic... 阅读全文
posted @ 2015-07-02 11:48 jianchao-li 阅读(267) 评论(0) 推荐(0) 编辑
摘要: This link suggests a concise C++ recursive solution. The original code may be hard to understand at first and I have rewritten the code below. You may... 阅读全文
posted @ 2015-07-02 11:35 jianchao-li 阅读(519) 评论(0) 推荐(0) 编辑
摘要: If you have solved the N-Queens problem, this one can be solved in a similar manner. Starting from the first row, we try each of its columns. If there... 阅读全文
posted @ 2015-07-01 22:28 jianchao-li 阅读(221) 评论(0) 推荐(0) 编辑
摘要: The idea is to use backtracking. In fact, the code below uses DFS, which involves backtracking in a recursive manner.The idea is also very simple. Sta... 阅读全文
posted @ 2015-07-01 21:16 jianchao-li 阅读(249) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 /* 4 * @param n: An integer 5 * @return: True or false 6 */ 7 bool checkPowerOf2(int n) { 8 ... 阅读全文
posted @ 2015-07-01 01:59 jianchao-li 阅读(423) 评论(0) 推荐(0) 编辑
摘要: Each time we find a match, increase the global counter by 1.For KMP, algorithm, you may refer to the following links which have nice explanations.KMP ... 阅读全文
posted @ 2015-06-30 17:55 jianchao-li 阅读(234) 评论(0) 推荐(0) 编辑
摘要: Well, this problem becomes a little trickier since there may be more than one majority element. But, there can be at most two of them. This can be pro... 阅读全文
posted @ 2015-06-30 11:54 jianchao-li 阅读(473) 评论(0) 推荐(0) 编辑
摘要: Well, if you have got this problem accepted, you may have noticed that there are 7 suggested solutions for this problem. The following passage will im... 阅读全文
posted @ 2015-06-30 11:32 jianchao-li 阅读(289) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 /** 4 * @param dictionary: a vector of strings 5 * @return: a vector of strings 6 */ 7 vector l... 阅读全文
posted @ 2015-06-30 00:03 jianchao-li 阅读(403) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 /** 4 * @param string: An array of Char 5 * @param length: The true length of the string 6 * @retur... 阅读全文
posted @ 2015-06-29 23:59 jianchao-li 阅读(374) 评论(0) 推荐(0) 编辑
摘要: 暴力解法(O(mn)): 1 class Solution { 2 public: 3 /** 4 * Returns a index to the first occurrence of target in source, 5 * or -1 if target is... 阅读全文
posted @ 2015-06-29 23:23 jianchao-li 阅读(348) 评论(0) 推荐(0) 编辑
摘要: 1 /** 2 * Definition of ListNode 3 * class ListNode { 4 * public: 5 * int val; 6 * ListNode *next; 7 * ListNode(int val) { 8 * ... 阅读全文
posted @ 2015-06-29 23:11 jianchao-li 阅读(259) 评论(0) 推荐(0) 编辑
摘要: Well, life gets difficult pretty soon whenever the same operation on array is transferred to linked list.First, a quick recap of insertion sort:Start ... 阅读全文
posted @ 2015-06-29 23:07 jianchao-li 阅读(164) 评论(0) 推荐(0) 编辑
摘要: 1 class Solution { 2 public: 3 /** 4 * @param A: sorted integer array A which has m elements, 5 * but size of A is m+n 6 ... 阅读全文
posted @ 2015-06-29 22:57 jianchao-li 阅读(439) 评论(0) 推荐(0) 编辑
上一页 1 ··· 8 9 10 11 12 13 14 15 16 ··· 20 下一页