Skip to content

Commit 3677249

Browse files
authored
Create 0938-range-sum-of-bst.kt
1 parent 0366401 commit 3677249

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kotlin/0938-range-sum-of-bst.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution {
2+
fun rangeSumBST(root: TreeNode?, low: Int, high: Int): Int {
3+
root?: return 0
4+
5+
return if (root.`val` > high) rangeSumBST(root.left, low, high)
6+
else if (root.`val` < low) rangeSumBST(root.right, low, high)
7+
else root.`val` +
8+
rangeSumBST(root.left, low, high) +
9+
rangeSumBST(root.right, low, high)
10+
}
11+
}

0 commit comments

Comments
 (0)