<p>Given an integer array <code>nums</code> where the elements are sorted in <strong>ascending order</strong>, convert <em>it to a </em><span data-keyword="height-balanced"><strong><em>height-balanced</em></strong></span> <em>binary search tree</em>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/18/btree1.jpg" style="width: 302px; height: 222px;" />
<pre>
<strong>Input:</strong> nums = [-10,-3,0,5,9]
<strong>Output:</strong> [0,-3,9,-10,null,5]
<strong>Explanation:</strong> [0,-10,5,null,-3,null,9] is also accepted:
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/18/btree2.jpg" style="width: 302px; height: 222px;" />
</pre>

<p><strong class="example">Example 2:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/02/18/btree.jpg" style="width: 342px; height: 142px;" />
<pre>
<strong>Input:</strong> nums = [1,3]
<strong>Output:</strong> [3,1]
<strong>Explanation:</strong> [1,null,3] and [3,1] are both height-balanced BSTs.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>4</sup></code></li>
	<li><code>-10<sup>4</sup> &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
	<li><code>nums</code> is sorted in a <strong>strictly increasing</strong> order.</li>
</ul>

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
     void MakeBst(vector<int>temp,TreeNode* root,int lb, int ub,int mid){
        if(lb>=ub)return;
        else if (lb == mid){
             TreeNode* ptr1 = new TreeNode(temp[ub]);
            root->right = ptr1;
            return;
        }
        else if(ub == mid){
                  TreeNode* ptr1 = new TreeNode(temp[lb]);
            root->left = ptr1;
            return;

        }
        int midi = (lb+mid)/2;
        TreeNode* ptr1 = new TreeNode(temp[midi]);
        root->left = ptr1;
        MakeBst(temp,ptr1,lb,mid-1,midi);
        int pidi = (mid+1+ub)/2;
        TreeNode*ptr2 = new TreeNode(temp[pidi]);
        root->right = ptr2;
        MakeBst(temp,ptr2,mid+1,ub,pidi);

    }
    TreeNode* sortedArrayToBST(vector<int>& nums) {
        
        int size = nums.size();
        int mid = size/2;
        TreeNode* root = new TreeNode(nums[mid]);
        MakeBst(nums,root,0,size-1,mid);
        return root;

        
    }
};
35144