Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6209ad0

Browse files
authored
Merge pull requestneetcode-gh#2107 from a93a/main
Create 0669-trim-a-binary-search-tree.kt
2 parentscf8bbcc +dbcab98 commit6209ad0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Example:
3+
* var ti = TreeNode(5)
4+
* var v = ti.`val`
5+
* Definition for a binary tree node.
6+
* class TreeNode(var `val`: Int) {
7+
* var left: TreeNode? = null
8+
* var right: TreeNode? = null
9+
* }
10+
*/
11+
classSolution {
12+
funtrimBST(root:TreeNode?,low:Int,high:Int):TreeNode? {
13+
if(root==null)
14+
returnnull
15+
if(root.`val`< low)
16+
return trimBST(root.right, low, high)
17+
elseif(root.`val`> high)
18+
return trimBST(root.left, low, high)
19+
root.left= trimBST(root.left, low, high)
20+
root.right= trimBST(root.right, low, high)
21+
return root
22+
}
23+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp