3
TreeNode *sortedArrayToBST(vector<int> &nums) {5
if (n == 0) // if no elements are present7
if (n == 1) // if only one element is present8
return new TreeNode(nums[0]); // create the root node with that element10
int mid = n / 2; // finding the position of the middle element in the array11
TreeNode *root = new TreeNode(nums[mid]); // create root node with mid element13
vector<int> l(nums.begin(), nums.begin() + mid); // left subarray14
vector<int> r(nums.begin() + mid + 1, nums.end()); // right subarray16
// using recursion to form the rest of the nodes :18
// the left nodes of the root must be smaller than root19
root->left = sortedArrayToBST(l);21
// the right nodes of the root must be greater than root22
root->right = sortedArrayToBST(r);