Wrong answer??? Python


  • 0
    Y

    I run the code in test mode successfully, with parameter [1,3]. However, it will fail while submitting the code. The code is shown as follow. Anyone knows the reason?

    Thanks ahead.

    0_1498462571405_a6a6bd9c-d025-4e5b-a57d-4803bba92258-image.png

    0_1498462591402_17c42303-9efe-4bcb-b2db-8f9ed623f0b5-image.png

    lst = list()
    def sortedListToBST(self, head):
        """
        :type head: ListNode
        :rtype: TreeNode
        """
        while(head is not None):
            self.lst.append(head.val)
            head = head.next
        bst = self.createBST(0, len(self.lst)-1)
        return bst
        
    def createBST (self, start, end):
        if start <= end :
            pivot = (start + end)/2
            node = TreeNode(self.lst[pivot])
            node.left = self.createBST(start, pivot-1)
            node.right = self.createBST(pivot+1, end)
            return node
        else:
            return None

Log in to reply
 

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