```
public int minDepth(TreeNode root) {
if (null == root) {
return 0;
}
int l = minDepth(root.left);
int r = minDepth(root.right);
if (l == 0 && r == 0) {
return 1;
} else if (l == 0 && r != 0) {
return r + 1;
} else if (l != 0 && r == 0) {
return l + 1;
} else{
int min = l < r ? l : r;
return min + 1;
}
}```
```