摘要:
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 阅读全文
摘要:
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 阅读全文
摘要:
Problem Description:Given twosparse matricesAandB, return the result ofAB.You may assume thatA's column number is equal toB's row number.Example:A = [... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
Problem Description:A 2d grid map ofmrows andncolumns is initially filled with water. We may perform anaddLandoperation which turns the water at posit... 阅读全文
摘要:
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 ... 阅读全文
摘要:
The idea is fairly straightforward: create an arrayaccuthat stores the accumulated sum fornumssuch thataccu[i] = nums[0] + ... + nums[i]in the initial... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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... 阅读全文
摘要:
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 ... 阅读全文
摘要:
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... 阅读全文