问题描述:
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 run(TreeNode *root) {
if(root==NULL)return 0;
else {
int i=run(root->left);
int j=run(root->right);
if(i==0||j==0)
return 1+i+j;
else
return (i<j)?i+1:j+1;
}
}
};