```
int minDepth(TreeNode* root) {
if(!root) return 0;
if(!root->left && !root->right) return 1;
int d_left=INT_MAX;
int d_right=INT_MAX;
if(root->left) d_left=minDepth(root->left)+1;
if(root->right) d_right=minDepth(root->right)+1;
return min(d_left,d_right);
}
```