669. Trim a Binary Search Tree

preorder, postorder 都可以做

```java
class Solution {
    public TreeNode trimBST(TreeNode node, int low, int high) {
        if (node == null) {
            return null;
        }
        node.left = trimBST(node.left, low, high); // 為了接上新結果, 要 = 回去
        node.right = trimBST(node.right, low, high);

        if (node.val < low) { // 放棄左邊, 接右邊就可以
            return node.right;
        }
        if (node.val > high) { // 放棄右邊, 接左邊就可以
            return node.left;
        }
        
        return node; // 在範圍內的值, 就不動回傳
    }
}
```

Last updated