# Definition for a binary tree node. # class TreeNode(object): # def __init__(self, x): # self.val = x # self.left = None # self.right = None class Solution(object): def constructMaximumBinaryTree(self, nums): """ :type nums: List[int] :rtype: TreeNode """ if not nums: return None ret = TreeNode(max(nums)) i = nums.index(ret.val) ret.left = self.constructMaximumBinaryTree(nums[:i]) ret.right = self.constructMaximumBinaryTree(nums[i + 1:] if len(nums) > i + 1 else None) return ret