111 Minimum Depth of Binary Tree
2015-03-17 12:19
260 查看
方法一:(深度优先搜索,记得单个结点深度为1,注意边界情况。) class Solution { public: int minDepth(TreeNode *root) { if(root==0) return 0; if(root->left==NULL&&root->right==NULL) return 1; int l=0x3f3f3f3f,r=0x3f3f3f3f; if(root->left!=NULL) l=1+minDepth(root->left); if(root->right!=NULL) r=1+minDepth(root->right); return min(l,r); } };
相关文章推荐
- [leetcode 111]Minimum Depth of Binary Tree
- 111 Minimum Depth of Binary Tree
- leetcode 111 Minimum Depth of Binary Tree C++
- [111] Minimum Depth of Binary Tree
- leetcode111——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
- leetcode111---Minimum Depth of Binary Tree
- 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-面试算法经典-Java实现】【111-Minimum Depth of Binary Tree(二叉树的最小深度)】
- Leetcode #111 Minimum Depth of Binary Tree
- #111 Minimum Depth of Binary Tree & #104 Maximum Depth of Binary Tree
- 111 Minimum Depth of Binary Tree
- leetcode-111 Minimum Depth of Binary Tree
- LeetCode #111:Minimum Depth of Binary Tree