Easy C++ recursive solution with Explanation
Approach\n Describe your approach to solving the problem. \nThe function first checks if the root is NULL. If it is, then it returns 0. If the root is not NULL,
# Approach\n<!-- Describe your approach to solving the problem. -->\nThe function first checks if the root is NULL. If it is, then it returns 0. If the root is not NULL, the function recursively calls itself for the left and right subtrees, and stores the sum of values in \'left\' and \'right\' variables respectively.\n\nThen, the function checks if the value of the root node falls within the given range. If it does, then it returns the sum of the root node\'s value, \'left\' and \'right\'. If it doesn\'t, then it returns \'left\' and \'right\' sum.\n\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(h)$$ where h is the height of the binary search tree\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    int rangeSumBST(TreeNode* root, int low, int high) {\n        if(root == NULL) return 0;\n        int left = rangeSumBST(root->left, low, high);\n        int right = rangeSumBST(root->right, low, high);\n        if(root->val >= low && root->val <= high){\n            return root->val + left+right;\n        }\n        return left+right;\n    }\n};\n```
['C++']