Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST. For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
(将有序数组转换为平衡二叉树)
Example:
1. 递归
根据平衡二叉树的定义:height差不大于1。因此从中间开始建立为根节点,左边的有序数组构建左子树,右边的有序数组构建右子树。具体实现过程如下:
1 | # Definition for a binary tree node. |