public class Solution {
public int RangeSumBST(TreeNode root, int low, int high) {
int sum = low <= root.val && root.val <= high ? root.val : 0;
if (root.left != null) {
sum += RangeSumBST(root.left, low, high);
}
if (root.right != null) {
sum += RangeSumBST(root.right, low, high);
}
return sum;
}
}
Source: https://leetcode.com/problems/range-sum-of-bst/
"Simplicity can't be bought later, it must be earned from the start" -- DB
Thursday, February 18, 2021
Leetcode Everyday: 938. Range Sum of BST. Easy
Labels:
leetcode
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment