leetcode--111. Minimum Depth of Binary Tree
来源:互联网 发布:用c语言制作病毒 编辑:程序博客网 时间:2024/05/21 05:44
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.
题解
和求最大深度类似,不过求最小深度需要注意的是,当一个节点只有左子树或者右子树的时候,不应取最小的那个作为深度。
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int minDepth(TreeNode* root) { if(root == NULL) return 0; int L = minDepth(root->left), R = minDepth(root->right); return 1 + (min(L, R) ? min(L, R) : max(L, ;R)) }};
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
- [leetcode] 111. Minimum Depth of Binary Tree
- 111. Minimum Depth of Binary Tree LeetCode
- 【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
- 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.[Leetcode]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
- Java设计模式-单例模式
- #UVA1635#Irrelevant Elements
- P1036 选数
- 解决WEB-INF/lib目录下的jar包无法用maven打包
- 监控impdp/expdp的进度方法
- leetcode--111. Minimum Depth of Binary Tree
- poj专题 - 初期数学
- 打造Android中万能BaseAdapter
- canvas粒子时钟
- 前端性能优化,前端开发注意的小细节
- poj3253——Fence Repair(哈夫曼)
- 作为it从业人员,如何写好一份可堪入目的简历?
- linux常用命令
- CSU-1111