Sum of BST Values in a Given Range
Intuition\n Describe your first thoughts on how to solve this problem. \nThe code aims to find the sum of values in a binary search tree (BST) that fall within 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe code aims to find the sum of values in a binary search tree (BST) that fall within a specified range [low, high]. It uses a preorder traversal to explore the tree, collecting node values into a list, and then sums up the values within the given range.\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTraverse the BST using preorder traversal.\nCollect all node values in the ans list.\nIterate through the list and sum up values within the specified range [low, high].\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(N)\n# Code\n```\n# Definition for a binary tree node.\n# class TreeNode:\n#     def __init__(self, val=0, left=None, right=None):\n#         self.val = val\n#         self.left = left\n#         self.right = right\nclass Solution:\n    def rangeSumBST(self, root: Optional[TreeNode], low: int, high: int) -> int:\n        ans = []\n        def preorder(root) :\n            if not root :\n                return \n            ans.append(root.val)\n            preorder(root.left)\n            preorder(root.right)\n        preorder(root)\n        sol = 0\n        for i in ans :\n            if (low <= i <= high) :\n                sol += i\n        return sol \n        \n        \n```
['Python3']