```
public class Solution {
public int minDepth(TreeNode root) {
if (root==null) return 0; // height is zero
int leftH = minDepth(root.left); // get left height
int rightH = minDepth(root.right); // get right height
if (leftH*rightH==0 && leftH!=rightH){ // only one of them is zero
return (leftH!=0?leftH:rightH)+1; // return non-zero one
}
return Math.min(leftH,rightH)+1; // else return the smaller one
}
}
```

Nothing special... logic is presented in the comments.