随笔分类 -  LeetCode Solutions

1 2 3 4 5 ··· 12 下一页
Solutions to problems on https://leetcode.com/problemset/algorithms/.
摘要:The code is as follows. The above code may be rewritten to make it more readable. c stands for the carry bit of adding two integers. The sum of two in 阅读全文
posted @ 2016-09-10 21:47 jianchao-li 阅读(372) 评论(0) 推荐(0)
摘要:A very typical application of hash maps. Since I am now learning Java, I code in Java. The following code uses toCharArray() and getOrDefault(), which 阅读全文
posted @ 2016-08-14 21:57 jianchao-li 阅读(524) 评论(0) 推荐(0)
摘要:Problem Description:Given twosparse matricesAandB, return the result ofAB.You may assume thatA's column number is equal toB's row number.Example:A = [... 阅读全文
posted @ 2015-12-03 13:39 jianchao-li 阅读(4581) 评论(0) 推荐(0)
摘要:This problem requires a new data structure --- Segment Tree. You may use this GeeksforGeeks article to get some ideas of it. However, the code in this... 阅读全文
posted @ 2015-11-23 17:14 jianchao-li 阅读(1508) 评论(0) 推荐(0)
摘要:Af first I read the title as "Addictive Number". Anyway, this problem can be solved elegantly using recursion. This post shares a nice recursive C++ c... 阅读全文
posted @ 2015-11-20 13:16 jianchao-li 阅读(871) 评论(0) 推荐(0)
摘要:Problem Description:A 2d grid map ofmrows andncolumns is initially filled with water. We may perform anaddLandoperation which turns the water at posit... 阅读全文
posted @ 2015-11-14 20:55 jianchao-li 阅读(7312) 评论(0) 推荐(0)
摘要:Very similar to Range Sum Query - Immutable, but we now need to compute a 2d accunulated-sum. In fact, if you work in computer vision, you may know a ... 阅读全文
posted @ 2015-11-12 22:00 jianchao-li 阅读(673) 评论(0) 推荐(0)
摘要:The idea is fairly straightforward: create an arrayaccuthat stores the accumulated sum fornumssuch thataccu[i] = nums[0] + ... + nums[i]in the initial... 阅读全文
posted @ 2015-11-10 13:43 jianchao-li 阅读(993) 评论(0) 推荐(0)
摘要:This post shares very detailed explanation of how to use binary search to find the boundaries of the smallest rectangle that encloses the black pixels... 阅读全文
posted @ 2015-11-08 21:00 jianchao-li 阅读(1285) 评论(0) 推荐(0)
摘要:This problem can be solved very elegantly using BFS, as in this post.The code is rewritten below in C++. 1 class Solution { 2 public: 3 vector rem... 阅读全文
posted @ 2015-11-05 15:38 jianchao-li 阅读(1438) 评论(0) 推荐(0)
摘要:A typical O(n^2) solution uses dynamic programming. Let's use lens[j] to denote the length of the LIS ending with nums[j]. The state equations arelens... 阅读全文
posted @ 2015-11-03 22:15 jianchao-li 阅读(412) 评论(1) 推荐(0)
摘要:This problem seems to be easy at the first glance, especially the problem gives a too much simpler example. Make sure you understand the problem by ma... 阅读全文
posted @ 2015-10-31 18:23 jianchao-li 阅读(354) 评论(0) 推荐(0)
摘要:Problem Description:Given a binary tree, find the length of the longest consecutive sequence path.The path refers to any sequence of nodes from some s... 阅读全文
posted @ 2015-10-30 16:55 jianchao-li 阅读(2287) 评论(0) 推荐(0)
摘要:I adopt a way similar to that of the OJ to serialize the binary tree. For the following tree, my serialization result is "1,2,3,null,null,4,5," (note ... 阅读全文
posted @ 2015-10-30 15:51 jianchao-li 阅读(850) 评论(0) 推荐(0)
摘要:Problem Description:A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, wher... 阅读全文
posted @ 2015-10-22 16:34 jianchao-li 阅读(3899) 评论(0) 推荐(1)
摘要:This post shares a very nice solution using two heaps: a max heap for the smaller half and a min heap for the larger half. The code is rewritten below... 阅读全文
posted @ 2015-10-19 23:53 jianchao-li 阅读(1613) 评论(0) 推荐(0)
摘要:Problem Description:You are playing the following Flip Game with your friend: Given a string that contains only these two characters:+and-, you and yo... 阅读全文
posted @ 2015-10-17 00:20 jianchao-li 阅读(6546) 评论(0) 推荐(0)
摘要:Problem Description:You are playing the following Flip Game with your friend: Given a string that contains only these two characters:+and-, you and yo... 阅读全文
posted @ 2015-10-15 13:54 jianchao-li 阅读(6213) 评论(0) 推荐(0)
摘要:Haha, an interesting problem. Just try to let your opponent start with a number that is an integer multiple of 4.1 class Solution {2 public:3 bool... 阅读全文
posted @ 2015-10-13 16:41 jianchao-li 阅读(215) 评论(0) 推荐(0)
摘要:Problem Description:Given apatternand a stringstr, find ifstrfollows the same pattern.Herefollowmeans a full match, such that there is a bijection bet... 阅读全文
posted @ 2015-10-12 00:08 jianchao-li 阅读(5014) 评论(0) 推荐(0)

1 2 3 4 5 ··· 12 下一页