Skip to content

Commit 5ffa62f

Browse files
solves range sum of bst
1 parent 69890f5 commit 5ffa62f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
| 929 | [Unique Email Addresses](https://leetcode.com/problems/unique-email-addresses) | [![Java](assets/java.png)](src/UniqueEmailAddresses.java) |
254254
| 933 | [Number of Recent Calls](https://leetcode.com/problems/number-of-recent-calls) | [![Java](assets/java.png)](src/NumberOfRecentCalls.java) |
255255
| 937 | [Reorder Data In Log Files](https://leetcode.com/problems/reorder-data-in-log-files) | [![Java](assets/java.png)](src/ReorderDataInLogFiles.java) |
256-
| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | |
256+
| 938 | [Range Sum of BST](https://leetcode.com/problems/range-sum-of-bst) | [![Java](assets/java.png)](src/RangeSumOfBST.java) |
257257
| 941 | [Valid Mountain Array](https://leetcode.com/problems/valid-mountain-array) | |
258258
| 942 | [DI String Match](https://leetcode.com/problems/di-string-match) | |
259259
| 944 | [Delete Columns to Make Sorted](https://leetcode.com/problems/delete-columns-to-make-sorted) | |

src/RangeSumOfBST.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class RangeSumOfBST {
2+
public int rangeSumBST(TreeNode root, int low, int high) {
3+
if (root == null) return 0;
4+
if (low <= root.val && root.val <= high) {
5+
return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high);
6+
}
7+
if (root.val < low) return rangeSumBST(root.right, low, high);
8+
return rangeSumBST(root.left, low, high);
9+
}
10+
}

0 commit comments

Comments
 (0)