您的位置:首页 > 其它

The Tree ||

2015-08-16 22:29 555 查看
Binary Tree Right Side View :*** This one is a little tricky, how to ensure there is only the most right node in the res list for each lvl. 学习中间变量的使用,找到正确的中间变量能简化问题,解决问题。Further
understand the way recursion works.

Construct Binary Tree from Inorder and Postorder Traversal :**** This question is very inspiring. Notice the return
condition of returning null. The overall logic is tricky but clear, find root through postorder(always at very end), then decide left and right through inorder(nodes are not duplicate!).

Lowest Common Ancestor of a Binary Tree :**** This one is tricky. Nothing much to say, remember it.

Recover Binary Search Tree : **** This one is tricky. (study this one withFlatten
Binary Tree to Linked List , see how this keep track of pre-node). Remember this one. See analysis here Code_Ganker

Binary Tree Maximum Path Sum: *** Tricky one. The variable to main and the variable to return is different. Notice that making sure L and R always
larger than 0 will simplify the process of maintaining max_value a lot.

Count Complete Tree Nodes : *** Brute force will take O(n) and ETL. Remember this one, which uses properties of complete Binary tree, which is there
must be one child subtree could be calculated by (1<<h) - 1 ! So we can skip scanning this subtree.

Validate Binary Search Tree : *** Tricky one. Very similar to Recover
Binary Search Tree . This could be done exactly follow the same way as recover BST though, but not necessary. Since we only need to discover any mis-order instance instead of fixing them, we only need to return true or false then. Remember this.
Especially when to update the pre variable.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: