1class Solution {2public TreeNode trimBST(TreeNode root, int low, int high) {3if (root == null) return root;4while (root.val < low || root.val > high) {5root = root.val < low ? root.right : root.left;6if (root == null) return root;7}8root.left = trimBST(root.left, low, high);9root.right = trimBST(root.right, low, high);10return root;11}12}