Find the sum between the given range in BST

In the given BST, find the sum between the given range in BST.

Solution)

public void rangeSum(TreeNode node, int min, int max) {
    if (node == null || node.val < min || node.val > max) return 0;
    return node.val + rangeSum(node.left, min, max) + rangeSum(node.right, min, max);
}

results matching ""

    No results matching ""