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 int minDepth(TreeNode root) {
if (root == null) return 0;
if(root.left == null && root.right == null) return 1; //叶子节点
int leftDepth = root.left != null ? minDepth(root.left): Integer.MAX_VALUE;
int rightDepth = root.right != null ? minDepth(root.right): Integer.MAX_VALUE;
return Math.min(leftDepth, rightDepth) + 1;
}