上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 20 下一页
摘要: Well, a dynamic programming problem. Let's first define its statedp[i][j]to be the number of distinct subsequences oft[0..i - 1]ins[0..j - 1]. Then we... 阅读全文
posted @ 2015-07-26 12:44 jianchao-li 阅读(227) 评论(0) 推荐(0) 编辑
摘要: Well, the idea is to search from thetop-rightelement and then reduce the range for further searching by comparisons betweentargetand the current eleme... 阅读全文
posted @ 2015-07-25 12:11 jianchao-li 阅读(213) 评论(0) 推荐(0) 编辑
摘要: This problem is more or less the same asFind Minimum in Rotated Sorted Array. And one key difference is as stated in the solution tag. That is, due to... 阅读全文
posted @ 2015-07-19 17:57 jianchao-li 阅读(177) 评论(0) 推荐(0) 编辑
摘要: As explained in the Solution tag, the key to solving this problem is to use invariants. We set two pointers:lfor the left andrfor the right. One key i... 阅读全文
posted @ 2015-07-19 15:57 jianchao-li 阅读(318) 评论(0) 推荐(0) 编辑
摘要: For those who have already solvedSearch in Rotated Sorted Array, this problem can be solved similarly using codes for that problem and simply adding c... 阅读全文
posted @ 2015-07-19 14:17 jianchao-li 阅读(269) 评论(0) 推荐(0) 编辑
摘要: This problem is a nice application of binary search. The key lies in how to determine the correct half fortarget. Since the array has been rotated, we... 阅读全文
posted @ 2015-07-18 22:22 jianchao-li 阅读(212) 评论(0) 推荐(0) 编辑
摘要: Well, in the case of a linked list instead of an array, the problem becomes easier. We just need to find the node that will be the new head of the lis... 阅读全文
posted @ 2015-07-17 07:39 jianchao-li 阅读(163) 评论(0) 推荐(0) 编辑
摘要: This problem, as stated in the problem statement, has a lot of solutions. Since the problem requires us to solve it in O(1) space complexity, I only s... 阅读全文
posted @ 2015-07-17 07:04 jianchao-li 阅读(161) 评论(0) 推荐(0) 编辑
摘要: The first answer in this link has a nice illustrative explanation.Suppose the given array is like [nums[0], nums[1], nums[2], nums[3]]. Then the resul... 阅读全文
posted @ 2015-07-16 14:38 jianchao-li 阅读(374) 评论(0) 推荐(0) 编辑
摘要: As the note in the problem statement, this problem has a straight-forward O(n)-space solution, which is to generate the inorder traversal results of t... 阅读全文
posted @ 2015-07-15 23:27 jianchao-li 阅读(206) 评论(0) 推荐(0) 编辑
摘要: This problem has a nice BFS structure. Let's illustrate it using the examplenums = [2, 3, 1, 1, 4]in the problem statement. We are initially at positi... 阅读全文
posted @ 2015-07-15 21:30 jianchao-li 阅读(209) 评论(0) 推荐(0) 编辑
摘要: This problem has a very concise solution in this link, just 4-lines. The code is rewritten below.1 class Solution {2 public:3 bool canJump(vector&... 阅读全文
posted @ 2015-07-15 20:20 jianchao-li 阅读(207) 评论(0) 推荐(0) 编辑
摘要: Well, this problem is just a trick. In fact, we cannot really delete the given node, but just delete its next node after copying the data of the next ... 阅读全文
posted @ 2015-07-15 13:44 jianchao-li 阅读(260) 评论(0) 推荐(0) 编辑
摘要: Note: If you feel unwilling to read the long codes, just take the idea with you. The codes are unnecessarily long due to the inconvenient handle of ma... 阅读全文
posted @ 2015-07-15 00:42 jianchao-li 阅读(250) 评论(0) 推荐(0) 编辑
摘要: Note: The following idea is in fact from the last answer inthis link, which leads to a clean code. I just reorganize it and add some explanations. I h... 阅读全文
posted @ 2015-07-14 23:55 jianchao-li 阅读(400) 评论(0) 推荐(0) 编辑
上一页 1 ··· 4 5 6 7 8 9 10 11 12 ··· 20 下一页