class Solution {
public:
int minDepth(TreeNode* root) {
if(!root) return 0;
int left=minDepth(root->left);
int right=minDepth(root->right);
if(!root->left||!root->right) return left+right+1;
else return min(left,right)+1;
}
};
Leetcode111(力扣111):二叉树的最小深度
最新推荐文章于 2024-01-13 07:30:00 发布