Use divide and conquer. If left or right return 0, just return max(right, left) to avoid null node problem.

```
class Solution {
public:
int minDepth(TreeNode* root) {
if(!root) return 0
int left = minDepth(root->left);
int right = minDepth(root->right);
return min(left==0?max(right,left):left, right==0?max(right, left):right) + 1;
}
};
```