/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode* mergeKLists(vector<ListNode*>& lists) {
vector<int> nums;
for(auto it = lists.begin();it != lists.end();it++)
{
ListNode* node = *it;
while(node)
{
nums.push_back(node->val);
node = node->next;
}
}
ListNode* ihead = new ListNode(0);
ListNode* node = ihead;
sort(nums.begin(),nums.end());
for(auto it = nums.begin();it != nums.end();it++)
{
node->next = new ListNode(*it);
node = node->next;
}
return ihead->next;
}
};
今天太忙啦,先这样打卡,明天补上!