For Fun :)
\n# Approach\n Describe your approach to solving the problem. \nRecursive Traversal: Use recursion to traverse the tree. It checks each node to see if its value
![image.png](https://assets.leetcode.com/users/images/d30d067e-904c-429a-a6a0-490663a1f03a_1704703975.4280899.png)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n**Recursive Traversal**: Use recursion to traverse the tree. It checks each node to see if its value falls within the given range.\n\n**Conditional Summation**: At each node, the solution adds the node\'s value to the sum if the value is between low and high (inclusive).\n\n**Base Case for Recursion**: The recursion stops when a null node is reached, which is a leaf\'s child in the BST.\n# Complexity\n- Time complexity: $$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:$$O(logN)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```C++ []\n//FAST I/O\n const static auto fast = [] {\n    ios_base::sync_with_stdio(false);\n    cin.tie(nullptr);\n    cout.tie(nullptr);\n    return 0;\n}();\n\nclass Solution {\npublic:\n    int rangeSumBST(TreeNode* root, int low, int high) {\n        return (root == nullptr) ? 0 : (((root->val <= high && root->val >= low) ? root->val : 0) + rangeSumBST(root->left, low, high) + rangeSumBST(root->right, low, high));\n    }\n};\n```\n```C# []\npublic class Solution {\n    public int RangeSumBST(TreeNode root, int low, int high) => (root == null) ? 0 : (((root.val <= high && root.val >= low) ? root.val : 0) + RangeSumBST(root.left, low, high) + RangeSumBST(root.right, low, high));\n}\n```\n```Java []\npublic class Solution {\n    public int rangeSumBST(TreeNode root, int low, int high) {\n        return (root == null) ? 0 : (((root.val <= high && root.val >= low) ? root.val : 0) + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high));\n    }\n}\n```\n
['C++', 'Java', 'C#']