Simple approach | Binary search algorithm
Intuition\nThe array is sorted, and you want to create a balanced BST.\n# The middle element of the array will be the root of the BST to maintain balance.\nRecu
# Intuition\n**The array is sorted, and you want to create a balanced BST.**\n# ***The middle element of the array will be the root of the BST to maintain balance.***\nRecursively construct the left subtree using elements to the left of the middle element and the right subtree using elements to the right of the middle element.\n\n# Approach\nstep 1. solve function is a recursive helper function that takes the array, along with low and high indices, representing the current range of elements to consider. \nstep 2. If the low index surpasses the high index, it returns nullptr since there are no elements in this range. \nstep 3. Otherwise, it calculates the middle index, creates a TreeNode with the corresponding value, and recursively calls itself for the left and right halves of the array. The constructed root node is then returned.\n\n# Complexity\n**Time complexity: O(n)**\nThe time complexity of this approach is O(n), where n is the number of elements in the array. Each element is visited exactly once during the construction of the BST,\n\n\n# Code\n```\n\nclass Solution {\npublic:\n    TreeNode* solve(vector<int>& nums,int low,int high){\n        if(low<=high){\n            int mid=low+(high-low)/2;\n            TreeNode* root=new TreeNode(nums[mid]);\n            root->left=solve(nums,low,mid-1);\n            root->right=solve(nums,mid+1,high);\n            return root;\n        }\n        return nullptr;\n    }\n    TreeNode* sortedArrayToBST(vector<int>& nums) {\n        return solve(nums,0,nums.size()-1);\n    }\n};\n```
['Binary Search', 'Binary Search Tree', 'Binary Tree', 'C++']