# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param num int整型一维数组
# @return TreeNode类
#
class Solution:
def sortedArrayToBST(self , num: List[int]) -> TreeNode:
# write code here
def dfs(arr):
if not arr: return None
l, r = 0, len(arr) - 1
mid = (l + r) // 2
node = TreeNode(arr[mid])
node.left = dfs(arr[:mid])
node.right = dfs(arr[mid + 1:])
return node
return dfs(num)