摘要: 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 阅读(363) 评论(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 阅读(514) 评论(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 阅读(4572) 评论(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 阅读(1493) 评论(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 阅读(860) 评论(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 阅读(7293) 评论(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 阅读(666) 评论(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 阅读(988) 评论(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 阅读(1278) 评论(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 阅读(1428) 评论(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 阅读(401) 评论(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 阅读(346) 评论(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 阅读(2278) 评论(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 阅读(843) 评论(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 阅读(3867) 评论(0) 推荐(1) 编辑