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

I also posted an alternative in my blog, which is identical to someone's posted solution.