Python solution
DFS recursive:\n\nclass Solution:\n    def rangeSumBST(self, root, L, R):\n        """\n        :type root: TreeNode\n        :type L: int\n        :type R: int
DFS recursive:\n```\nclass Solution:\n    def rangeSumBST(self, root, L, R):\n        """\n        :type root: TreeNode\n        :type L: int\n        :type R: int\n        :rtype: int\n        """\n        def dfs(root):\n            if not root:\n                return\n            if L <= root.val <= R:\n                self.res += root.val\n            if L <= root.val:\n                dfs(root.left)\n            if R >= root.val:\n                dfs(root.right)\n        self.res = 0\n        dfs(root)\n        return self.res\n```\nDFS iterative:\n```\nclass Solution:\n    def rangeSumBST(self, root, L, R):\n        """\n        :type root: TreeNode\n        :type L: int\n        :type R: int\n        :rtype: int\n        """\n        stack = [root]\n        res = 0\n        while stack:\n            u = stack.pop()\n            if L <= u.val <= R:\n                res += u.val\n            if u.left and u.val >= L:\n                stack.append(u.left)\n            if u.right and u.val <= R:\n                stack.append(u.right)\n        return res\n```
[]