class Solution {

public:

int minDepth(TreeNode* root) {

if(root == NULL){

return 0;

}

if(root->left == NULL && root->right == NULL){

return 1;

}

return helper(root);

```
}
int helper(TreeNode* root){
if(root->left == NULL && root->right == NULL){
return 1;
}
if(root->left == NULL){
return helper(root->right) + 1;
}
if(root->right == NULL){
return helper(root->left) + 1;
}
return 1 + min(helper(root->left), helper(root->right));
}
```

};