Skip to content

Commit 4b8e162

Browse files
committed
Add prompt for LC 669 Trim a BST
1 parent 9591718 commit 4b8e162

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

669. Trim a Binary Search Tree.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
3+
Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of the elements that will remain in the tree (i.e., any node's descendant should remain a descendant). It can be proven that there is a unique answer.
4+
5+
Return the root of the trimmed binary search tree. Note that the root may change depending on the given bounds.
6+
7+
8+
Example 1:
9+
Input: root = [1,0,2], low = 1, high = 2
10+
Output: [1,null,2]
11+
12+
Example 2:
13+
Input: root = [3,0,4,null,2,null,null,1], low = 1, high = 3
14+
Output: [3,2,null,1]
15+
16+
17+
Constraints:
18+
- The number of nodes in the tree is in the range [1, 104].
19+
- 0 <= Node.val <= 104
20+
- The value of each node in the tree is unique.
21+
- root is guaranteed to be a valid binary search tree.
22+
= 0 <= low <= high <= 104
23+
24+
*/
25+
26+
/**
27+
* Definition for a binary tree node.
28+
* function TreeNode(val, left, right) {
29+
* this.val = (val===undefined ? 0 : val)
30+
* this.left = (left===undefined ? null : left)
31+
* this.right = (right===undefined ? null : right)
32+
* }
33+
*/
34+
35+
/**
36+
* @param {TreeNode} root
37+
* @param {number} low
38+
* @param {number} high
39+
* @return {TreeNode}
40+
*/
41+
const trimBST = (root, low, high) => {};

0 commit comments

Comments
 (0)