package leetcode;

/**
 * https://leetcode.com/problems/range-sum-of-bst/
 */
public class Problem938 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int rangeSumBST(TreeNode root, int L, int R) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem938 prob = new Problem938();
        TreeNode root = new TreeNode(10);
        root.left = new TreeNode(5);
        root.left.left = new TreeNode(3);
        root.left.right = new TreeNode(7);
        root.right = new TreeNode(15);
        root.right.right = new TreeNode(18);
        System.out.println(prob.rangeSumBST(root, 7, 15)); // 32
        System.out.println(prob.rangeSumBST(root, 6, 15)); // 32

        root = new TreeNode(10);
        root.left = new TreeNode(5);
        root.left.left = new TreeNode(3);
        root.left.right = new TreeNode(7);
        root.right = new TreeNode(15);
        root.right.left = new TreeNode(13);
        root.right.right = new TreeNode(18);
        root.left.left.left = new TreeNode(1);
        root.left.right.left = new TreeNode(6);
        System.out.println(prob.rangeSumBST(root, 6, 10)); // 23
    }
}

@@ -331,661 +331,335 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem938 prob = new Problem938();%0A        TreeNode root = new TreeNode(10);%0A        root.left = new TreeNode(5)
+IntRef sum = new IntRef();%0A        inOrder(root, L, R, sum);%0A        return sum.sum
 ;%0A    
+%7D%0A%0A
     
-root.left.left = new TreeNode(3);%0A        root.left.right = new TreeNode(7)
+private static class IntRef %7B%0A        private int sum
 ;%0A    
+%7D%0A%0A
     
-root.right = new TreeNode(15);%0A        root.right.right = new TreeNode(18);%0A        System.out.println(prob.rangeSumBST(root, 7, 15)); // 32%0A        System.out.println(prob.rangeSumBST(root, 6, 15)); // 32%0A%0A        root = new TreeNode(10);%0A        root.left = new TreeNode(5);%0A        root.left.left = new TreeNode(3);%0A        root.left.right = new TreeNode(7
+private static void inOrder(TreeNode root, int l, int r, IntRef sum) %7B%0A        if (root == null) %7B%0A            return;%0A        %7D%0A        inOrder(root.left, l, r, sum
 );%0A 
@@ -669,287 +669,128 @@
     
+if (
 root.
-right = new TreeNode(15);%0A        root.right.left = new TreeNode(13);%0A        root.right.right = new TreeNode(18);%0A        root.left.left.left = new TreeNode(1);%0A        root.left.right.left = new TreeNode(6);%0A        System.out.println(prob.rangeSumBST(root, 6, 10)); // 23
+val %3E= l && root.val %3C= r) %7B%0A            sum.sum += root.val;%0A        %7D%0A        inOrder(root.right, l, r, sum);
 %0A   

Solve problem 938