随笔分类 -  lintCode

上一页 1 2 3 4 5 6 下一页

Binary Tree Level Order Traversal II
摘要:This is very similar to Binary Tree Level Order Traversal. Just reverse the order of the list. ArrayList has API- > add(int index, Element) or Collect 阅读全文

posted @ 2017-06-13 09:06 codingEskimo 阅读(92) 评论(0) 推荐(0)

Binary Tree Longest Consecutive Sequence III
摘要:Note: This question is good summary for this kind of problem. 1) Once you get the root, loop through all the children. Get the max up/down/max from th 阅读全文

posted @ 2017-06-07 08:50 codingEskimo 阅读(109) 评论(0) 推荐(0)

Binary Tree Longest Consecutive Sequence II
摘要:Note: O(n) This question is the extension of the version one. The longest consecutive Sequence could be found in "Parent->Children" or "Children -> Pa 阅读全文

posted @ 2017-06-07 07:54 codingEskimo 阅读(117) 评论(0) 推荐(0)

Binary Tree Longest Consecutive Sequence
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { ... 阅读全文

posted @ 2017-06-07 06:22 codingEskimo 阅读(84) 评论(0) 推荐(0)

Lowest Common Ancestor III
摘要:Note: This is question is very similar to LCA original. The only difference is that the node may not exist. So if the node is not exsit, of course the 阅读全文

posted @ 2017-06-07 05:45 codingEskimo 阅读(141) 评论(0) 推荐(0)

Lowest Common Ancestor II
摘要:Note 这道题和一不同,给了一个Node向上回溯的可能,所以不需要recersive的找。因为之前的那个题不能回头,所以必须先到最下面(或者找的A和B)。这道题我们只需要把A和B的path记住就可以了,然后比较path中从root到A或者B,一直到开始不一样的时候停止,那个最后一个一样的就是LCA 阅读全文

posted @ 2017-06-06 11:27 codingEskimo 阅读(400) 评论(0) 推荐(0)

Lowest Common Ancestor
摘要:Note: // 在root为根的二叉树中找A,B的LCA: // 如果找到了就返回这个LCA // 如果只碰到A,就返回A // 如果只碰到B,就返回B // 如果都没有,就返回null Just consider relationship between left, right and root 阅读全文

posted @ 2017-06-02 08:03 codingEskimo 阅读(151) 评论(0) 推荐(0)

Flatten Binary Tree to Linked List
摘要:Note: It is easier to use divided conquer. As you can see, the question is just to add right to left's last. Here we care more about last then the top 阅读全文

posted @ 2017-06-02 06:54 codingEskimo 阅读(117) 评论(0) 推荐(0)

Kth Largest Element
摘要:Node: Quick Select: Avg O(N) Thought: put all the element less(more) than pivot to the first part, the rest to the second part. And Kth only falls to 阅读全文

posted @ 2017-06-02 06:09 codingEskimo 阅读(121) 评论(0) 推荐(0)

Subtree with Maximum Average
摘要:Important: using a/b < c/d => a*d < c*b to check, we don't need to do the type transfer For the tree, if we need to get the max/min tree node, it is b 阅读全文

posted @ 2017-06-01 08:29 codingEskimo 阅读(91) 评论(0) 推荐(0)

Merge Sorted Array
摘要:class Solution { /** * @param A: sorted integer array A which has m elements, * but size of A is m+n * @param B: sorted integer array B which has n elements * @retu... 阅读全文

posted @ 2017-05-31 09:15 codingEskimo 阅读(88) 评论(0) 推荐(0)

Merge Two Sorted Arrays
摘要:class Solution { /** * @param A and B: sorted integer array A and B. * @return: A new sorted integer array */ public int[] mergeSortedArray(int[] A, int[] B) { // Write... 阅读全文

posted @ 2017-05-31 09:07 codingEskimo 阅读(107) 评论(0) 推荐(0)

Balanced Binary Tree
摘要:Note:a balaced tree needs to be balaced all the time. So it is important remember the status of each subtree. If it is not balaced in the middle, the 阅读全文

posted @ 2017-05-31 09:00 codingEskimo 阅读(88) 评论(0) 推荐(0)

Minimum Subtree
摘要:/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left ... 阅读全文

posted @ 2017-05-31 08:32 codingEskimo 阅读(77) 评论(0) 推荐(0)

Binary Tree Paths
摘要:/** * Definition of TreeNode: * public class TreeNode { * public int val; * public TreeNode left, right; * public TreeNode(int val) { * this.val = val; * this.left ... 阅读全文

posted @ 2017-05-31 07:20 codingEskimo 阅读(93) 评论(0) 推荐(0)

Minimum Depth of Binary Tree
摘要:This question is a little bit harder than the Max Depth. We only compare the depth of the leaf node. If it is missing one side, this level shouldn't b 阅读全文

posted @ 2017-05-31 06:13 codingEskimo 阅读(73) 评论(0) 推荐(0)

Merge Sort
摘要:public class Solution { /** * @param A an integer array * @return void */ public void sortIntegers2(int[] A) { // Write your code here if (A == null || A.length... 阅读全文

posted @ 2017-05-31 05:37 codingEskimo 阅读(90) 评论(0) 推荐(0)

Median
摘要:O(n) worst, O(nlogn) average. Use quickSort This is quickSort 阅读全文

posted @ 2017-05-28 06:26 codingEskimo 阅读(160) 评论(0) 推荐(0)

Smallest Rectangle Enclosing Black Pixels
摘要:Note: 约等于O(nlogn) 阅读全文

posted @ 2017-05-28 05:47 codingEskimo 阅读(128) 评论(0) 推荐(0)

Wood Cut
摘要:Note: 审题: 注意也有一种情况是: 一共有N个元素,要k个,但有不需要从每一个块去取, 只需要从其中的一些取。所以这里end开始应该取最大的element。而且有可能完全取不到,所以start应该从0开始取。剩下的和copy book那道题想法一致。 阅读全文

posted @ 2017-05-28 04:46 codingEskimo 阅读(179) 评论(0) 推荐(0)

上一页 1 2 3 4 5 6 下一页

导航