```
int minDepth(TreeNode *root) {
if(!root) return 0;
// meet leaf node
if(!root->left && !root->right){
return 1;
}
// meet internal node
else{
if(!root->left || !root->right) return root->left?minDepth(root->left)+1:minDepth(root->right)+1;
else return min(minDepth(root->left), minDepth(root->right))+1;
}
}
```