求深度的变种,但不能单纯的选最短的那一条,要选有路的最短的那一条。
int minDepth(TreeNode* root) {
if(!root) return 0;
else if(root->left&&root->right) return min(minDepth(root->left),minDepth(root->right))+1;
else if(root->left) return minDepth(root->left)+1;
else return minDepth(root->right)+1;
}