Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- """
- index_of_max = 0
- value_of_max = nums[0]
- for i in range(len(nums)):
- if nums[i] > value_of_max:
- value_of_max = n
- index_of_max = i
- # split it on the max
- left_nums = [:i]
- right_nums = [i+1:]
- result = TreeNode(value_of_max)
- result.left = self.constructMaximumBinaryTree(left_nums)
- result.right = self.constructMaximumBinaryTree(right_nums)
- return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement