Minimum Depth of Binary Tree(求二叉树的最小深度)
2016-09-21 21:54
435 查看
class Solution {
public:
int run(TreeNode *root) {
if (root==NULL){
return 0;
}
int l = run(root->left);
int r = run(root->right);
if (l==0||r==0){
return 1+l+r; //当前节点要么有一个分支,要么是根节点
}
return 1 + min(l,r);
}
};
public:
int run(TreeNode *root) {
if (root==NULL){
return 0;
}
int l = run(root->left);
int r = run(root->right);
if (l==0||r==0){
return 1+l+r; //当前节点要么有一个分支,要么是根节点
}
return 1 + min(l,r);
}
};
相关文章推荐
- [LeetCode-111] Minimum Depth of Binary Tree (二叉树最小深度)
- 【二叉树的递归】01二叉树的最小深度【Minimum Depth of Binary Tree】
- [LeetCode] Minimum Depth of Binary Tree 二叉树最小深度
- Minimum Depth of Binary Tree 二叉树的最小深度
- Minimum Depth of Binary Tree 求二叉树最小高度/深度@LeetCode
- [LeetCode] Minimum Depth of Binary Tree 二叉树的最小深度
- 【LeetCode】Minimum Depth Of Binary Tree二叉树的最小深度 - Easy
- Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度 [java]
- 求二叉树的最小深度 Minimum Depth of Binary Tree
- LeetCode Minimum Depth of Binary Tree 最小深度二叉树
- [Java代码] [Leetcode] Maximum and Minimum Depth of Binary Tree 二叉树的最小最大深度
- Leetcode Minimum Depth of Binary Tree 二叉树最小深度
- LeetCode OJ:Minimum Depth of Binary Tree(二叉树的最小深度)
- lintcode minimum-depth-of-binary-tree 二叉树最小深度
- 【LeetCode-面试算法经典-Java实现】【111-Minimum Depth of Binary Tree(二叉树的最小深度)】
- [Leetcode] The minimum depth of binary tree二叉树的最小深度
- LeetCode OJ 之 Minimum Depth of Binary Tree(二叉树的最小深度)
- LeetCode:111_Minimum Depth of Binary Tree | 二叉树的最小深度 | Easy
- 【LeetCode-面试算法经典-Java实现】【111-Minimum Depth of Binary Tree(二叉树的最小深度)】
- 【leetcode】Minimum Depth of Binary Tree 二叉树的最小深度 (JAVA)