You are given a list nums that is sorted from small to large. Turn it into a height-balanced binary search tree. In a height-balanced tree, the left and right subtrees of every node differ in height by at most 1.
Which tree to return: many height-balanced trees are right, but the judge compares your answer with one fixed tree. The rule: in every range of the list, the root is the element at index (length divided by 2, rounded down), counting from 0. When the length is even, this is the upper of the two middle elements. Build the left part and the right part in the same way.
How the judge passes the data
Examples
Example 1:
Input: nums = [2,4,6,8]
Output: [6,4,8,2]
Explanation: The length is 4, so the root is index 2, which is 6. The left part [2,4] has root 4 with 2 as its left child. The right part [8] is a single node.
Example 2:
Input: nums = [-5,-1,3,7,11]
Output: [3,-1,11,-5,null,7]
Explanation: The root is index 2, which is 3. The left part [-5,-1] gives root -1 with left child -5. The right part [7,11] gives root 11 with left child 7.
Example 3:
Input: nums = [4]
Output: [4]
Explanation: One element gives a tree with one node.