654. 最大二叉树





class Solution(object):
    def constructMaximumBinaryTree(self, nums):
        """
        :type nums: List[int]
        :rtype: TreeNode
        """
        if not nums:
            return
        rootval = max(nums)
        rootindex = nums.index(rootval)
        root = TreeNode(rootval)
        root.left = self.constructMaximumBinaryTree(nums[:rootindex])
        root.right = self.constructMaximumBinaryTree(nums[rootindex + 1:])
        return root

posted @ 2020-08-30 17:47  人间烟火地三鲜  阅读(148)  评论(0编辑  收藏  举报