描述
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
代码
class Solution {
public:
//int min=88888888;
int run(TreeNode *root) {
if(root==NULL){
return 0;
}
int left=run(root->left);
int right=run(root->right);
if(left==0||right==0){
return left+right+1;
}
return 1+min(left,right);
}
int min(int a,int b){
return a<b?a:b;
}
};