class Solution {
public:
int minDepth(TreeNode* root) {
if(!root) return 0;
if(!root->left && !root->right) return 1;
int left_depth = root->left? minDepth(root->left):INT_MAX;
int right_depth = root->right? minDepth(root->right) :INT_MAX;
return min(left_depth, right_depth) + 1;
}
};
网友评论