给定一个整数数组,其元素为先序排列,将其转换为高度平衡的二叉查找树。
Input: nums = [-10,-3,0,5,9]
Output: [0,-3,9,-10,null,5]
Explanation: [0,-10,5,null,-3,null,9] is also accepted:
Input: nums = [1,3]
Output: [3,1]
Explanation: [1,null,3] and [3,1] are both height-balanced BSTs.
有序数组的中间点即二叉查找树的根节点,将有序数组从中间位置分为左右两部分,左边部分为根节点的左子节点部分,右边部分为右子节点部分。递归左边部分和右边部分,即可得到二叉查找树。
具体代码见下面的链接
有序数组转换为二叉查找树