111. Minimum Depth of Binary Tree
来源:互联网 发布:淘宝开店身份证照片图 编辑:程序博客网 时间:2024/05/19 13:21
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.
计算一棵二叉树的最小深度,也就是根节点到叶节点的最小长度。使用递归的方法,要注意叶节点是左右节点都为空。
代码:
class Solution{public:int minDepth(TreeNode* root) {if(!root) return 0;if(!root->left) return minDepth(root->right) + 1;if(!root->right) return minDepth(root->left) + 1;return min(minDepth(root->right), minDepth(root->left)) + 1;}};
阅读全文
0 0
- LeetCode 111. Minimum Depth of Binary Tree
- [LeetCode]111.Minimum Depth of Binary Tree
- 【LeetCode】111.Minimum Depth of Binary Tree
- [Leetcode] 111. Minimum Depth of Binary Tree
- 111.Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 【LeetCode】111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- LeetCode *** 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree
- spring项目开发小记2
- 博客flag日志
- 使用DownloadManager进行版本更新(兼容7.0)
- 驼峰式命名的字符串与数据库字段下划线大写方式的转换
- 游戏服务端之间内部通讯数的据包解析
- 111. Minimum Depth of Binary Tree
- java-抽象类
- mysql创建删除用户
- findContours
- 访问家庭内网资源
- [译] TensorFlow 白皮书
- CSS3中:nth-child和:nth-of-type的区别深入理解
- WiFi-ESP8266入门开发(四)-设置软热点
- R语言数据基础