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 @   人间烟火地三鲜  阅读(148)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示