# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
lens = len(nums)
if not lens:
root = None
else:
rootIndex = lens // 2
root = TreeNode(nums[rootIndex])
root.left = self.sortedArrayToBST(nums[:rootIndex])
root.right = self.sortedArrayToBST(nums[rootIndex+1:])
return root
将有序数组转换为二叉搜索树,力扣题目,解法为从中间截开,每次分半,建立节点即可