leetcode 111:二叉树的最小深度
本题也相对简单,只需要简单迭代即可
int minDepth(TreeNode*root){
if(root==NULL)
return 0;
TreeNode*l=root->left;
TreeNode*r=root->right;
if(l==NULL&&r==NULL)
return 1;
else if(l!=NULL&&r==NULL)
return 1+minDepth(l);
else if(l==NULL&&r!=NULL)
return 1+minDepth(r);
else
return 1+std::min(minDepth(l),minDepth(r));
}