leetcode669
二叉树的题目无脑递归做,关键还是在三板斧——确定参数和返回值、终止条件和单层逻辑体
public TreeNode trimBST(TreeNode root, int low, int high) {
if(root == null) return null;
if(root.val < low) {
if(root.right != null) return trimBST(root.right, low, high);
else return null;
}
if(root.val > high) {
if(root.left != null) return trimBST(root.left, low, high);
else return null;
}
root.left = trimBST(root.left, low, high);
root.right = trimBST(root.right, low, high);
return root;
}