5.4.1 Minimum Depth of Binary Tree
来源:互联网 发布:mac os虚拟机 编辑:程序博客网 时间:2024/06/05 03:06
Notes: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Solution: 1. Recursion. Pay attention to cases when the non-leaf node has only one child. 2. Iteration + Queue. Contributed by SUN Mian(孙冕). */ /** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */int BiTree::minDepth(BiNode*root)
{
if (!root)
return 0;
return 1 + min(minDepth(root->lchild), minDepth(root->rchild));
}
{
if (!root)
return 0;
return 1 + min(minDepth(root->lchild), minDepth(root->rchild));
}
0 0
- 5.4.1 Minimum Depth of Binary Tree
- 5.4.1 Minimum Depth of Binary Tree
- leetcode-1-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
- css中div高度自适应
- 5个在线制作APP开发工具介绍和APP公司酷站欣赏
- 面试题 47
- Eclipse设置断点无效的解决办法
- Linux-shell下的作业管理
- 5.4.1 Minimum Depth of Binary Tree
- 细话Java:"失效"的private修饰符
- 数据库oracle for update of和for update区别
- API性能测试基本性能指标及要求
- 关于android开发中出现中文乱码
- openssl编程之服务端
- gethostbyname用法
- Rectangle Area
- 记AWS+Drupal Happy Hour 150610—— AWS Active 分享