My simple python solution


  • -3
    Z

    Use sorting in a list

    def mergeKLists(self, lists):
        all = []
        for node in lists:
            while node:
                all.append(node.val)
                node = node.next
        all.sort()
    
        if not all: return []
        result = inloop = ListNode(all[0])
        for n in range(1,len(all)):
            inloop.next = ListNode(all[n])
            inloop = inloop.next
        return result

Log in to reply
 

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