###########################################################################
#                                                                         #
# Author: Daniel Mock                                                     #
#                                                                         #
# Purpose: To document progress in learning algorithms & data structures  #
#                                                                         #
# References: This question was generated by leetcode.com. The solution   #
# to the question was generated by Daniel Mock.                           #
#                                                                         #
###########################################################################


# 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:
        #COME BACK TO THIS ONE!!
        if len(nums) > 0:

            i = len(nums) // 2
            root = TreeNode(nums[i])
            root.left = self.sortedArrayToBST(nums[:i])
            root.right = self.sortedArrayToBST(nums[i+1:])
            return root


        '''if len(nums) == 0: return None
        if len(nums) == 1: return TreeNode(nums[0])
        if len(nums) == 2:
            node1 = TreeNode(nums[1])
            node2 = TreeNode(nums[0])
            node1.left = node2
            return node1
        if len(nums)%2 == 0:
            half = int(len(nums)/2)
            #print(half)
        else:
            half = int((len(nums)-1)/2)
            #print(half)
        head = TreeNode(nums[half])
        ref = head
        lst = []
        for i in reversed(nums[:half]):
            #print(i)
            ref.left = TreeNode(i)
            ref = ref.left
        ref = head
        for i in nums[half+1:]:
            print(i)
            ref.right = TreeNode(i)
            ref = ref.right
        return head
        '''
