Skip to content

Commit b3d096b

Browse files
Create 0938-range-sum-of-bst.java
1 parent 3677249 commit b3d096b

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

java/0938-range-sum-of-bst.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*--------------------------
2+
Time Complexity: O(n)
3+
Space Complexity: O(n)
4+
---------------------------*/
5+
class Solution {
6+
public int rangeSumBST(TreeNode root, int low, int high) {
7+
if(root == null)
8+
return 0;
9+
if(root.val > high)
10+
return rangeSumBST(root.left, low, high);
11+
if(root.val < low)
12+
return rangeSumBST(root.right, low, high);
13+
return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high);
14+
}
15+
}

0 commit comments

Comments
 (0)