@lei.liu.509 Hi there, I'm amazed by your solution and I have two questions here:

As you merge without "erase", is your algorithm not reclaiming the space? Suppose a list like this:

[[1, 2], [2, 3]], does it ultimately become [[1, 2], [1, 2, 2, 3]] ?

I tried to re-implement your algorithm by setting the "merged" lists to nullptr to reclaim space, but it runs really slow, I'm a newbie in C++, could you please take a glimpse at my code and let me know if I'm missing something obvious? Thanks!

class Solution {
public:
ListNode *mergeKLists(vector<ListNode *> &lists) {
if (lists.empty()) {
return nullptr;
}
int index = 0; // index of the next non-null list inside lists
while (index < lists.size() - 1) {
lists[index + 1] = MergeTwoLists(lists[index], lists[index + 1]);
lists[index] = nullptr; // if not reclaim space
++index;
}
return lists.back();
}
ListNode * MergeTwoLists(ListNode * l1, ListNode * l2) {
if (l1 == nullptr) return l2;
if (l2 == nullptr) return l1;
if (l1->val <= l2->val) {
l1->next = MergeTwoLists(l1->next, l2);
return l1;
} else { // l1->val > l2->val
l2->next = MergeTwoLists(l2->next, l1);
return l2;
}
}
};