Share python solution

  • -3

    This solution probably isn't what's expected for this problem.
    But its' fast :D

    # Definition for singly-linked list.
    # class ListNode:
    #     def __init__(self, x):
    #         self.val = x
    # = None
    class Solution:
        # @param {ListNode[]} lists
        # @return {ListNode}
        def mergeKLists(self, lists):
            lists = [lis for lis in lists if lis is not None]
            if not lists:
                return None
            vals = []
            for head in lists:
                while head is not None:
                    head =
            head = ListNode(vals[0])
            itr = head
            for i in vals[1:]:
       = ListNode(i)
                itr =
            return head

  • 0

    This solution isn't necessarily a bad solution. It's still O(n log n) anyways.

Log in to reply

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