```
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
bool cmp(ListNode *a,ListNode *b){
if(a->val<=b->val) return true;
else return false;
}
class Solution{
public:
ListNode *mergeKLists(vector<ListNode *> &lists){
vector<ListNode*> v;
int len=lists.size();
for(int i=0;i<len;i++) if(lists[i]!=NULL) v.push_back(lists[i]);
sort(v.begin(),v.end(),cmp);
len=v.size();
ListNode *head,*t;
head=t=new ListNode(-1);
while(len>0){
t->next=v[0];
t=t->next;
v[0]=v[0]->next;
if(v[0]==NULL) v.erase(v.begin());
else move(v,len);
len=v.size();
}
return head->next;
}
void move(vector<ListNode*> &v,int &len){
ListNode *t;
for(int i=0;i<len-1;i++){
if(v[i+1]!=NULL&&v[i]->val>v[i+1]->val){ t=v[i+1]; v[i+1]=v[i]; v[i]=t;}
else break;
}
}
};
```