```
class Solution {
public:
ListNode* mergeKLists(vector<ListNode*>& lists) {
int n = lists.size();
if(n==0) return NULL;
ListNode* head[n];
for(int i=0;i<n;i++) {
head[i] = lists[i];
}
while(n>1) {
for(int i=0;i*2<n;i++) {
head[i] = mergeTwoLists(head[i*2],(i*2+1) >= n?NULL:head[i*2+1]);
}
n = (n+1) / 2;
}
return head[0];
}
};
```