We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1abd2ad commit 5e51b1cCopy full SHA for 5e51b1c
Trees/TrimBinarySearchTree.java
@@ -0,0 +1,25 @@
1
+package Trees;
2
+
3
+public class TrimBinarySearchTree {
4
+ static class TreeNode {
5
+ int val;
6
+ TreeNode left,right;
7
+ }
8
9
+ private TreeNode trimBST(TreeNode root, int low,int high) {
10
+ if(root == null) return null;
11
12
+ if(root.val >= low && root.val <= high) {
13
+ root.left = trimBST(root.left,low,high);
14
+ root.right = trimBST(root.right,low,high);
15
16
+ else if(root.val < low) {
17
+ root = trimBST(root.right,low,high);
18
19
+ else if(root.val > high) {
20
+ root = trimBST(root.left,low,high);
21
22
23
+ return root;
24
25
+}
0 commit comments