[Java] Runtime: 0ms, faster than 100% || Recursive + Iterative solutions
Complexity\n- Time complexity: O(N)\n- Space complexity: O(N)\n\n# Approach\nDepth-First Search\n\n# Code\nRecursive Implementation \n\nclass Solution {\n    pr
# Complexity\n- Time complexity: O(N)\n- Space complexity: O(N)\n\n# Approach\nDepth-First Search\n\n# Code\nRecursive Implementation \n```\nclass Solution {\n    private int sum = 0;\n    public int rangeSumBST(TreeNode root, int low, int high) {\n        if (root == null) return sum;\n        if (root.val >= low && root.val <= high) sum += root.val;\n        if (low < root.val) rangeSumBST(root.left, low, high);\n        if (root.val < high) rangeSumBST(root.right, low, high);\n        return sum;\n    }\n}\n```\n\nIterative Implementation\n```\nclass Solution {\n    public int rangeSumBST(TreeNode root, int low, int high) {\n        int sum = 0;\n        Stack<TreeNode> stack = new Stack<>();\n        stack.push(root);\n\n        while (!stack.empty()) {\n            TreeNode current = stack.pop();\n            if (current == null) continue;\n            if (current.val >= low && current.val <= high) sum += current.val;\n            if (low < current.val) stack.push(current.left);\n            if (current.val < high) stack.push(current.right);\n        }\n        return sum;\n    }\n}\n```\n\n![\u0421\u043D\u0438\u043C\u043E\u043A \u044D\u043A\u0440\u0430\u043D\u0430 2022-12-07 \u0432 06.04.34.png](https://assets.leetcode.com/users/images/efd4433e-de08-4faa-ac6d-0e80535a2838_1670382321.6916676.png)\n\n
['Java']