摘要:
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... 阅读全文
摘要:
Well, the idea is to search from thetop-rightelement and then reduce the range for further searching by comparisons betweentargetand the current eleme... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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&... 阅读全文
摘要:
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 ... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文