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

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0