06 2017 档案

摘要:This question is standard level BSF. From this question, we can see the best time to mark a node is the time when it is added to a queue. 阅读全文

posted @ 2017-06-16 07:36 codingEskimo 阅读(125) 评论(0) 推荐(0)

摘要:Note: This is to count the level. At beginning, since there are so many zombies, we need to add all of them to the Queue to start with. It is differen 阅读全文

posted @ 2017-06-15 11:22 codingEskimo 阅读(131) 评论(0) 推荐(0)

摘要:This is Matrix Problem which can be converted to BSF: Loop through each node, if it is island, find the edge. Inside the mark them all as sea. So it w 阅读全文

posted @ 2017-06-15 07:46 codingEskimo 阅读(93) 评论(0) 推荐(0)

摘要:Only Path :判断是否只存在一个拓扑排序的序列 只需要保证队列中一直最多只有1个元素即可 tricky part:1) org has all the nodes. That is why each time there should only be 1 element in the que 阅读全文

posted @ 2017-06-15 06:17 codingEskimo 阅读(217) 评论(0) 推荐(0)

摘要:The same as I: 阅读全文

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

摘要:Note: 1) For integer node 0~n, we don't need a hashmap, we can just use array to act like a map; 2) How to initial List[] is very important 3) We need 阅读全文

posted @ 2017-06-14 08:38 codingEskimo 阅读(124) 评论(0) 推荐(0)

摘要:Topological Sorting is very important, almost every company has a question related to it. Goal: To find an proper order making the front nodes are ind 阅读全文

posted @ 2017-06-14 06:52 codingEskimo 阅读(184) 评论(0) 推荐(0)

摘要:Note: BSF: if it needs to check the value, should check it when it is coming from Queue. The logic is most clear to do it there. This question is to a 阅读全文

posted @ 2017-06-14 06:06 codingEskimo 阅读(194) 评论(0) 推荐(0)

摘要:This question is the same as Binary Tree Treverse in Level Order. Instead of a list, we need ListNode to remeber the result. The tricky part is that w 阅读全文

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

摘要:Similar to Binary Tree Level Order Travel, just need to add a flag to remeber the order. Change the order to opposite after the level is over. 阅读全文

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

摘要: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 阅读(96) 评论(0) 推荐(0)

摘要:This question is very important: 1) Serialization: a. Don't try to do all the things at once. The first step is to get a list of all the tree node. Th 阅读全文

posted @ 2017-06-13 08:42 codingEskimo 阅读(154) 评论(0) 推荐(0)

摘要: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 阅读(117) 评论(0) 推荐(0)

摘要: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 阅读(126) 评论(0) 推荐(0)

摘要:/** * 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 阅读(88) 评论(0) 推荐(0)

摘要: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 阅读(144) 评论(0) 推荐(0)

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

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

摘要: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 阅读(156) 评论(0) 推荐(0)

摘要: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 阅读(124) 评论(0) 推荐(0)

摘要: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 阅读(128) 评论(0) 推荐(0)

摘要: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 阅读(102) 评论(0) 推荐(0)

导航