```
void findMin(struct TreeNode* node, int* minSoFar, int prev)
{
if (node == NULL)
{
return;
}
if (node->left == NULL && node->right == NULL)
{
if (prev+1 < *minSoFar)
{
*minSoFar = prev+1;
}
}
findMin(node->left, minSoFar, prev+1);
findMin(node->right, minSoFar, prev+1);
}
int minDepth(struct TreeNode* root) {
int minSoFar = INT_MAX;
if (root == NULL)
return 0;
findMin(root, &minSoFar, 0);
return minSoFar;
}
```