摘要:
Just treat the Nested List as a tree, and dfs it: private int sum =0; public int depthSum(List<NestedInteger> nestedList) { helper(nestedList, 1); ret 阅读全文
摘要:
The simplest way that I can think to solve this problem is using a PriorityQueue: public int[][] kClosest(int[][] points, int k) { PriorityQueue<int[] 阅读全文
摘要:
For example, if the int[] w ={3,14,1,7}, we can make a presum array based on it: int[] presums = {3, 17, 18, 25} We using Ramdom's nextInt() to genera 阅读全文
该文被密码保护。 阅读全文
摘要:
This problem can be solved by using the solution of 236. Lowest Common Ancestor of a Binary Tree. While the tree here is a binary search tree, so the 阅读全文
摘要:
This problem is just as same as "235. Lowest Common Ancestor of a Binary Search Tree", the only difference is, 235 is two points, 1676 is 1~n points. 阅读全文
摘要:
The first solution of this problem can be based on the 236. Lowest Common Ancestor of a Binary Tree too: public Node lowestCommonAncestor(Node p, Node 阅读全文
摘要:
When we get this problem, we need to confirm the following 2 questions: 1. Can root, p or q be null? (No) 2. Are both p and q in the tree (No, either 阅读全文
摘要:
When we get this problem, we need to confirm the following 3 questions: 1. Can root, p or q be null? (No) 2. Are both p and q in the tree (yes) 3. Can 阅读全文
摘要:
Although this is an easy question, but it is prone to bugs, and the code can be better. Following is my first solution, didn't use the feature of BST. 阅读全文
摘要:
For sparse venctors, there might be too many "0"s in the array. What we need to do is only abstract the items which are not "0". We store these non-ze 阅读全文
摘要:
My first solution is use two skacks, one stack store index, another one store value, the time complexity is O(n). public int[] findBuildings(int[] hei 阅读全文