Skip to content

Commit d15ace6

Browse files
committed
Update index.ts
1 parent 2c30297 commit d15ace6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
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
1+
import { TreeNode } from "../mod.ts";
2+
export default trimBST;
3+
function trimBST(
4+
root: TreeNode | null,
5+
low: number,
6+
high: number,
7+
): TreeNode | null {
8+
if (!root) return null;
59

6-
if(root.val<low)return trimBST(root.right,low,high)
10+
if (root.val < low) return trimBST(root.right, low, high);
711

12+
if (root.val > high) return trimBST(root.left, low, high);
813

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))
14+
return new TreeNode(
15+
root.val,
16+
trimBST(root.left, low, high),
17+
trimBST(root.right, low, high),
18+
);
1219
}

0 commit comments

Comments
 (0)