Leetcode 111, Minimum Depth of Binary Tree
2016-10-23 07:40
489 查看
public int minDepth(TreeNode root) {
if(root == null)
return 0;
int left = minDepth(root.left);
int right = minDepth(root.right);
if(root.left == null){
return right + 1;
}else if(root.right == null){
return left + 1;
}
return Math.min(left, right) + 1;
}
refer: http://blog.csdn.net/linhuanmars/article/details/19660209
if(root == null)
return 0;
int left = minDepth(root.left);
int right = minDepth(root.right);
if(root.left == null){
return right + 1;
}else if(root.right == null){
return left + 1;
}
return Math.min(left, right) + 1;
}
refer: http://blog.csdn.net/linhuanmars/article/details/19660209
相关文章推荐
- 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: Minimum Depth of Binary Tree [111]
- Java for 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_question_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, Easy] Minimum Depth of Binary Tree
- [leetcode 111] Minimum Depth of Binary Tree
- leetcode_question_111 Minimum Depth of Binary Tree
- [leetcode-111]Minimum Depth of Binary Tree(C语言)
- 【LeetCode 111_二叉树_遍历】Minimum Depth of Binary Tree