class Solution(object): def mergeKLists(self, lists): ans =  heap =  for i in xrange(len(lists)): if lists[i]: heapq.heappush(heap, (lists[i].val, lists[i])) while heap: top = heapq.heappop(heap) ans.append(top) if top.next: heapq.heappush(heap, (top.next.val, top.next)) return ans
@Ipeq1 very clever and efficient. Only question is, you are returning a python list type, rather a sorted linked list. Personally I think it's fine. but wonder if this could pass the test.