package com.fishercoder.solutions;

import com.fishercoder.common.classes.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class _938 {
    public static class Solution1 {
        public int rangeSumBST(TreeNode root, int L, int R) {
            if (root == null) {
                return 0;
            }
            List<Integer> list = new ArrayList<>();
            dfs(root, L, R, list);
            return list.stream().mapToInt(num -> num).sum();
        }

        private void dfs(TreeNode root, int l, int r, List<Integer> list) {
            if (root == null) {
                return;
            }
            if (root.val <= r && root.val >= l) {
                list.add(root.val);
            }
            dfs(root.left, l, r, list);
            dfs(root.right, l, r, list);
        }
    }
}

@@ -240,16 +240,21 @@
 int 
-L
+low
 , int 
-R
+high
 ) %7B%0A
@@ -403,12 +403,17 @@
 ot, 
-L, R
+low, high
 , li

refactor 938