Compile Error with Python???


  • 0
    B

    Hi talent programmers, this is the first time I have meet "Compile Error" with Python. Can anyone tell me what's wrong?

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    #         self.next = None
    
    import Queue
    
    class Solution:
        # @param a list of ListNode
        # @return a ListNode
        def mergeKLists(self, lists):
            
            # Using a priorityQueue which size up to K to maintain who's in
            pq = Queue.PriorityQueue()
            for i in range(len(lists)):
                if lists[i]:
                    pq.put((lists[i].val, i))
                    lists[i] = lists[i].next
                    
            if pq.empty: return None # Handle all empty entry
            
            dummy = index = ListNode(0)
            
            while not pq.empty():
                val, i = pq.get()
                index.next = ListNode(val)
                index = index.next
                if lists[i]:
                    pq.put((lists[i].val, i))
                    lists[i] = lists[i].next
    
            return dummy.next

Log in to reply
 

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