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.
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.
相关文章推荐
- CSS样式 初学
- 如何在自己的Windows系统上 架设服务器并开发网站,然后连入外网供外界访问?(JDK+Tomcat+花生壳)
- Word Break
- Microsoft Dynamics CRM 2015 数据管理 功能 介绍
- Microsoft Dynamics CRM 2015 数据管理 功能 介绍
- 函数指针C++和回调函数
- 在VMware做虚拟映射进行网络连接的步骤
- 梦想永远那么近——《白箱》后日谈
- 机房重构VB.Net版进行中
- MongoDB查询内嵌文档
- glibc源码
- HDU 2276 & FZU 1692 (矩阵快速幂+循环同构优化)
- [线段树]hdu5316
- SpringMVC+MyBatis整合(3)特别篇SpringMVC配置
- ArrayAdapter的使用
- python使用libssh2连接linux
- 项目实战之玩转div+css制作自定义形状
- 在Ubuntu上配置django环境系统架构命令
- vijos - P1286座位安排 (DP状态压缩 + 组合数 + python)
- 从docker-hub和docker-registry看优秀的后端服务设计实现