Skip to content

Commit 2c30297

Browse files
authored
Create index.ts
1 parent 7c2ff80 commit 2c30297

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

trim-a-binary-search-tree/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import {TreeNode}from"../mod.ts"
2+
export default trimBST
3+
function trimBST(root: TreeNode | null, low: number, high: number): TreeNode | null {
4+
if(!root)return null
5+
6+
if(root.val<low)return trimBST(root.right,low,high)
7+
8+
9+
if(root.val>high)return trimBST(root.left,low,high)
10+
11+
return new TreeNode(root.val, trimBST(root.left,low,high), trimBST(root.right,low,high))
12+
}

0 commit comments

Comments
 (0)