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