class Solution {
public TreeNode trimBST(TreeNode root, int low, int high) {
if(root==null) return null;
if(root.val<low) //如果当前节点值比最小值小
{
TreeNode right=trimBST(root.right,low,high); //修剪他的右子树,返回右子树(同时忽略了root即自动删除)
return right;
}
else if(root.val>high){
TreeNode left=trimBST(root.left,low,high); //修剪左子树,返回左子树
return left;
}
root.right=trimBST(root.right,low,high); //在范围内则分别修建左右子树
root.left=trimBST(root.left,low,high);
return root;
}
}