Java Recursive and Iterative
\n    public int rangeSumBST(TreeNode root, int L, int R) {\n        if (root == null) return 0;\n        if (root.val <= L) return rangeSumBST(root.right, L, R
```\n    public int rangeSumBST(TreeNode root, int L, int R) {\n        if (root == null) return 0;\n        if (root.val <= L) return rangeSumBST(root.right, L, R) + (root.val == L ? root.val : 0);\n        if (root.val >= R) return rangeSumBST(root.left, L, R) + (root.val == R ? root.val : 0);\n        return rangeSumBST(root.left, L, R) + root.val + rangeSumBST(root.right, L, R);\n    }\n```\n\n```\n    public int rangeSumBST(TreeNode root, int L, int R) {\n        Stack<TreeNode> st = new Stack<>();\n        st.add(root);\n        int sum = 0;\n        while (!st.isEmpty()){\n            TreeNode n = st.pop();\n            if (n == null) continue;\n            if (n.val >= L && n.val <= R) sum += n.val;\n            if (n.val > L) st.push(n.left);\n            if (n.val < R) st.push(n.right);\n        }\n        return sum;\n    }\n```\n
[]