- [二叉树]111. Minimum Depth of Binar
- 二叉树的最小、最大深度以及平衡二叉树
- leetcode:111. Minimum Depth of B
- 111. Minimum Depth of Binary Tre
- 111. Minimum Depth of Binary Tre
- 111. Minimum Depth of Binary Tre
- 111. Minimum Depth of Binary Tre
- 111. Minimum Depth of Binary Tre
- 111. Minimum Depth of Binary Tre
- 111. Minimum Depth of Binary Tre
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.
public class Solution {
public int minDepth(TreeNode root) {
if(root == null)
return 0;
int Left = minDepth(root.left);
int Right = minDepth(root.right);
if(Left==0&&Right==0)
return 1;
if(Left==0)
Left = Integer.MAX_VALUE;
if(Right==0)
Right = Integer.MAX_VALUE;
return (Left>Right)? (Right+1):(Left+1);
}
}
网友评论