Easy recursive approach🚀|beats 97%📊📊
Intuition\nGiven the array is sorted, we let the middle element to be the root of the BST, ensuring an equal number of elements on both sides of the root, which
# Intuition\nGiven the array is sorted, we let the middle element to be the root of the BST, ensuring an equal number of elements on both sides of the root, which helps maintain the height-balanced property.\nAlso we know that the left elements of array from middle lie in the left side of the BST and the right elements of array from middle lie in the right side of the BST.\n\n# Approach\nusing recursion for forming the nodes.\nBase case is if high and low pointer points to same element then returning the node with the same element and when there is no element left then returning nullptr.\nthe left of node is the element which is in the middle of the low pointer and the current mid pointer and so on.\nthe right pointer is the element which is in the middle of the high pointer and the current mid pointer and so on. \n\n# Complexity\n- Time complexity:\nO(n)\nEach element in the array is processed once to create a tree node.\n\n- Space complexity:\nO(n)\nThe recursion stack depth can go up to O(logn) due to the nature of balanced trees. However, we also need space to store the tree nodes, which is 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    TreeNode* helper(vector<int>& nums,int high,int low){\n        if(low>high){\n            return nullptr;\n        }\n        int mid=(high+low)/2;\n        TreeNode* Node=new TreeNode(nums[mid]);\n        if(high==low){\n            return Node;\n        }\n        Node->left=helper(nums,mid-1,low);\n        Node->right=helper(nums,high,mid+1);\n        return Node;\n    }\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        TreeNode* root=helper(nums,nums.size()-1,0);\n        return root;\n    }\n};\n```
['Array', 'Divide and Conquer', 'Binary Search Tree', 'Recursion', 'Binary Tree', 'C++']