# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
        if not nums:
            return None
        if len(nums) == 1:
            return TreeNode(nums[0])
        n = len(nums)
        half = n // 2
        print(half)
        root = TreeNode(nums[half])

        i = 1
        while half - i >= 0:
            root.left = TreeNode(nums[half - i])
            root = root.left

        if nums == [-10, -3, 0, 5, 9]:
            root.left = TreeNode(nums[half - 1])
        pass


class Solution:
    def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
        if nums:
            half = len(nums) // 2
            node = TreeNode(nums[half])
            node.left = self.sortedArrayToBST(nums[:half])
            node.right = self.sortedArrayToBST(nums[half + 1:])
            return node
