Leetcode in Java && Oracle
421 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-24_17-35-55.png
43.3 KB
#N938. Range Sum of BST
problem link

#solution
class Solution {
int sum=0;
public int rangeSumBST(TreeNode root, int low, int high) {

if(root == null) {
return 0;
}
if(low<=root.val&&high>=root.val) sum+=root.val;

if(root.val>low){
rangeSumBST(root.left, low, high);
}
if(root.val<=high){
rangeSumBST(root.right, low, high);
}

return sum;
}
}