669. 修剪二叉搜索树
根据根节点的值和区间进行对比,来判断递归哪个子树,
class Solution {
public:
TreeNode* trimBST(TreeNode* root, int low, int high) {
if(root==NULL)return root;
if(root->val < low)return trimBST(root->right,low,high);
else if(root->val >high)return trimBST(root->left,low,high);
else{
if(root->left)root->left = trimBST(root->left,low,high);
if(root->right)root->right = trimBST(root->right,low,high);
}
return root;
}
};