Minimum Depth of Binary Tree
来源:互联网 发布:ringdivas 淘宝 编辑:程序博客网 时间:2024/04/30 21:34
注意如果不设置lmin与rmin等于0时,将其设置为最大值,则会计算出在倒数第二个节点终止的最小深度。但是深度一定要在叶子节点截止。
还有注意,return要返回min之后再加1.
class Solution { public: int minDepth(TreeNode* root) { if(root == NULL) return 0; TreeNode* p = root; int lmin = minDepth(p->left); int rmin=minDepth(p->right); if(lmin == 0 && rmin == 0) return 1; if(lmin == 0) lmin = INT_MAX; if(rmin == 0) rmin = INT_MAX; return min(lmin,rmin)+1; } };
0 0
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- Minimum Depth of Binary Tree
- 最长回文子串 与 最长回文子序列
- 存储-杂
- 打字练习感悟
- HDU 2102 A计划 (DFS)
- Openstack组件实现原理 — Glance架构(V1/V2)
- Minimum Depth of Binary Tree
- open-webkit-sharp使用
- JAVA——RandomAccessFile类
- 判断单链表中是否有环,环的长度,环的入口节点
- Intellj IDEA 快捷方式及设置优化
- 8小时外实践系列(六) - 在阿里云服务器上搭建GitLab(草稿)
- Android之Widget
- vector的用法
- jenkins使用 (三)centos安装git客户端