没什么难度的,刚开始又马虎了。。。
int minDepth(TreeNode *root) {
if(root==NULL)
return 0;
if (root->left==NULL&&root->right!=NULL)
{
return minDepth(root->right)+1;
}
else
{
if (root->left!=NULL&&root->right==NULL)
{
return minDepth(root->left)+1;
}
else
{
if (root->left!=NULL&&root->right!=NULL)
{
//return minDepth(root->right)+1;
int leftMinDepth = minDepth(root->left);
int rightMinDepth = minDepth(root->right);
return leftMinDepth<rightMinDepth?leftMinDepth+1:rightMinDepth+1;
}
else
{
return 1;
}
}
}
}