随笔分类 -  LeetCode Solutions

上一页 1 2 3 4 5 6 7 8 9 10 ··· 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:Hash TableThis idea uses a hash table to record the times of appearances of each letter in the two stringssandt. For each letter ins, it increases the... 阅读全文
posted @ 2015-08-01 14:14 jianchao-li 阅读(300) 评论(0) 推荐(0)
摘要:To solve this problem, you first need to understand it well. The key problem is tell the difference of scramble from permutations. You may refer to th... 阅读全文
posted @ 2015-08-01 11:58 jianchao-li 阅读(215) 评论(0) 推荐(0)
摘要:Well, this problem seems to be a little tricky at first glance. However, the idea (taken from this link) is really simple. Let's take the equation 2*3... 阅读全文
posted @ 2015-07-27 23:32 jianchao-li 阅读(431) 评论(0) 推荐(0)
摘要: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 阅读(244) 评论(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 阅读(219) 评论(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 阅读(187) 评论(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 阅读(326) 评论(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 阅读(280) 评论(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 阅读(224) 评论(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 阅读(171) 评论(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 阅读(168) 评论(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 阅读(380) 评论(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 阅读(211) 评论(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 阅读(228) 评论(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 阅读(215) 评论(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 阅读(268) 评论(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 阅读(260) 评论(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 阅读(407) 评论(0) 推荐(0)
摘要:Well, an interesting problem. If you draw some examples on a white board and try to figure out the regularities, you may have noticed that the key to ... 阅读全文
posted @ 2015-07-14 21:35 jianchao-li 阅读(242) 评论(0) 推荐(0)
摘要:Well, since we need to make a deep copy of the list and nodes in the list have arandom pointer that may point to any node in the list (or NULL), we ne... 阅读全文
posted @ 2015-07-14 12:35 jianchao-li 阅读(213) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 7 8 9 10 ··· 12 下一页