range sum of bst leetcode java

Solutions on MaxInterview for range sum of bst leetcode java by the best coders in the world

showing results for - "range sum of bst leetcode java"
Samuel
30 Jun 2020
1class Solution {
2    public int rangeSumBST(TreeNode root, int low, int high) {
3    if(root == null)
4        return 0;
5    
6    if(root.val > high)
7    {
8        return rangeSumBST(root.left,low,high);
9    }  
10    else if(root.val < low)
11    {
12        return rangeSumBST(root.right,low,high);
13    }
14    else
15    {
16       return root.val + rangeSumBST(root.left,low,high) + rangeSumBST(root.right,low,high);
17    }
18        
19}
20}