Skip to content

Commit

Permalink
Leetcode/938
Browse files Browse the repository at this point in the history
  • Loading branch information
herrera-ignacio committed Jan 8, 2024
1 parent db9873a commit 6fcc4f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
- [901: Stock plan](problems/leetcode/901) - Monotonic stack
- [905: Sort array by parity](problems/leetcode/905) - Easy - Array
- [907: Sum of subarray minimums](problems/leetcode/907) - Monotonic stack
- [938: Range sum of BST](problems/leetcode/938) - Easy - Tree
- [941: Valid mountain array](problems/leetcode/941) - Easy - Array
- [947 - Most stones removed with same row or column](problems/leetcode/947)
- [976: Largest perimeter triangle](problems/leetcode/976)
Expand Down
25 changes: 25 additions & 0 deletions problems/leetcode/938/solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Definition for a binary tree node.
* function TreeNode(val, left, right) {
* this.val = (val===undefined ? 0 : val)
* this.left = (left===undefined ? null : left)
* this.right = (right===undefined ? null : right)
* }
*/
/**
* @param {TreeNode} root
* @param {number} low
* @param {number} high
* @return {number}
*/
const rangeSumBST = (root, low, high) => {
let sum = 0;
if (root) {
if (low <= root.val && root.val <= high) {
sum += root.val;
}
sum += rangeSumBST(root.left, low, high)
sum += rangeSumBST(root.right, low, high);
}
return sum;
}

0 comments on commit 6fcc4f9

Please sign in to comment.