class Solution {
public:
ListNode* mergeKLists(vector<ListNode*>& lists) {
if(lists.size()==0)
return nullptr;
ListNode* head = lists[0];
for(int i = 1;i < lists.size();i++){
if(lists[i])
head = merge(head,lists[i]);
}
return head;
}
ListNode* merge(ListNode* l1, ListNode* l2){
if(!l1) return l2;
if(!l2) return l1;
if(l1->val <= l2->val){
l1 -> next = merge(l1->next, l2);
return l1;
}else {
l2 -> next = merge(l1,l2->next);
return l2;
}
}
};
08-16
324
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)