Python Very Simple Recursion


  • 0
    S
        def constructMaximumBinaryTree(self, nums):
            """
            :type nums: List[int]
            :rtype: TreeNode
            """
            if len(nums) < 1:
                return None
            node = TreeNode(max(nums))
            index = nums.index(node.val)
            node.left = self.constructMaximumBinaryTree(nums[:index])
            node.right = self.constructMaximumBinaryTree(nums[index+1:])
            return node
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.