class Solution {
public:
int minDepth(TreeNode *root) {
if(root==nullptr){
return 0;
}
if(root->left==nullptr){
return minDepth(root->right)+1;
}else if(root->right==nullptr){
return minDepth(root->left)+1;
}else{
return min(minDepth(root->right),minDepth(root->left))+1;
}
}
};