class Solution {
public:
TreeNode* trimBST(TreeNode* root, int low, int high) {
if(root==nullptr) return nullptr;
if(root->val>high){
return trimBST(root->left,low,high);
}else if(root->val<low){
return trimBST(root->right,low,high);
}else{
root->left=trimBST(root->left,low,high);
root->right=trimBST(root->right,low,high);
}
return root;
}
};
刷题记录第八十天-修剪二叉搜索树
最新推荐文章于 2024-07-22 21:51:19 发布