111. Minimum Depth of Binary Tree
3
/ \
9 20
/ \
15 7class Solution {
public int minDepth(TreeNode root) {
if (root == null) return 0;
int left = minDepth(root.left), right = minDepth(root.right);
return left == 0 && right == 0? 1: left == 0? right + 1: right == 0? left + 1: Math.min(left, right) + 1;
}
}Last updated
Was this helpful?