You are given an integer array sorted in ascending order. Your task is to convert it into a height-balanced Binary Search Tree (BST).
A BST is considered height-balanced if:
Return the root of any valid height-balanced BST.
Input: nums = [-10,-3,0,5,9]
Output: [0,-3,9,-10,null,5]
Explanation: Picking the middle element as the root at each step produces a height-balanced BST. Other valid balanced BSTs are also accepted.
Input: nums = [1,3]
Output: [3,1]
Explanation: Either element may be chosen as the root; the resulting BST must remain height-balanced.
Input: nums = []
Output: []
Explanation: An empty array produces an empty tree.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
1 2 3 4 5 6 7
4 2 6 1 3 5 7
2 4 6 8 10
6 4 8 2 null null 10