Answers for "range sum bst leetcode"

2

Range Sum of BST leetcode java

class Solution {
    public int rangeSumBST(TreeNode root, int low, int high) {
    if(root == null)
        return 0;
    
    if(root.val > high)
    {
        return rangeSumBST(root.left,low,high);
    }  
    else if(root.val < low)
    {
        return rangeSumBST(root.right,low,high);
    }
    else
    {
       return root.val + rangeSumBST(root.left,low,high) + rangeSumBST(root.right,low,high);
    }
        
}
}
Posted by: Guest on April-12-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language