```
int minDepth(TreeNode *root) {
return root==NULL? 0 : helper(root,0);
}
int helper(TreeNode* n, int d) {
if (n == NULL) return INT_MAX;
if (!n->left && !n->right) return d+1;
int l = helper(n->left, d+1);
int r = helper(n->right, d+1);
return min(l,r);
}
```