异曲同工之妙。
int findDepth(struct TreeNode* root,int step){
if(root->left == NULL&&root->right == NULL)
return step+1;
int leftStep = 0;
int rightStep = 0;
if(root->left)
leftStep = findDepth(root->left,step+1);
if(root->right)
rightStep = findDepth(root->right,step+1);
if(leftStep == 0)
return rightStep;
else if(rightStep == 0)
return leftStep;
else
return (leftStep < rightStep)?leftStep:rightStep;
}
int minDepth(struct TreeNode* root) {
if(!root)
return 0;
return findDepth(root,0);
}