```
int minDepth(TreeNode* root) {
if (root == NULL) return 0;
if (root->left == NULL || root->right == NULL)
return max( minDepth(root->left)+1, minDepth(root->right)+1 );
return min( minDepth(root->left)+1, minDepth(root->right)+1 );
}
```