从零开始Leetcode – Day 18
Binary Search Tree Iterator
https://leetcode.com/problems/binary-search-tree-iterator/
- 这里是用stack 来实习左中右, inorder 遍历。
- 实现stack, push和pop, LIFO
1 | /** |
https://leetcode.com/problems/binary-search-tree-iterator/
1 | /** |
https://leetcode.com/problems/binary-tree-inorder-traversal/
明天写非递归。
、、、
/**
};
var helper = function(root, res){
if(root === null){
return;
}
helper(root.left, res);
res.push(root.val);
helper(root.right, res);
}
、、、
https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
1 注意考虑起始条件, 和终止条件。
2 晚上做不了算法题, 白天做过的,到了晚上不能debug.
3 所有题目要重做一次, 才会产生效果。
1 | /** |
https://leetcode.com/problems/count-complete-tree-nodes/
注意直接递归会超时, log(N)
1 | var countNodes = function(root) { |
https://leetcode.com/problems/convert-sorted-list-to-binary-search-tree/
1 | /** |
https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/
http://blog.csdn.net/linhuanmars/article/details/23904883
前2天得太难了,跳过。以后碰到太难的直接跳过。 明天继续Angular之旅。快要看完了, 加油~~!!
1 | /** |
https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/
递归时有点复杂, 明天把把11,12的一起干了。 明天开始进入angular.
1 | var buildTree = function(inorder, postorder) { |
https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/
今天把 preorder, inorder, postorder. traversal 就是MLR, LMR, LRM. 递归思想, 每次看成一个3个节点的树。
http://blog.csdn.net/linhuanmars/article/details/24389549
明天早上在把它完成。
1 | /** |
##Binary Tree Level Order Traversal
不是很熟悉 curNum, lastNum. 理解得不够透彻。早点休息, 明天再努力。
1 | /** |
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
1 | $ hexo new "My New Post" |
More info: Writing
1 | $ hexo server |
More info: Server
1 | $ hexo generate |
More info: Generating
1 | $ hexo deploy |
More info: Deployment