int min = INT_MAX;

void minLength (struct TreeNode *node, int prev)

{

if(node == NULL)

{

return;

}

```
prev++;
if(node->left == NULL && node->right == NULL )
{
if(prev < min)
{
min = prev;
}
return;
}
if(node->left)
minLength(node->left, prev);
if(node->right)
minLength(node->right, prev);
```

}

int minDepth(struct TreeNode* root) {

```
if(root == NULL)
return 0;
```

minLength(root, 0);

return min;

}