int n=lists.size();
ListNode *dumy=new ListNode(-1);
ListNode *prev=dumy;
dumy->next=NULL;
priority_queue<int,vector ,greater> pq;
for(int i=0;i<n;i++)
{
ListNode *ptr=lists[i];
while(ptr!=NULL)
{
pq.push(ptr->val);
ptr=ptr->next;
}
}
while(!pq.empty())
{
ListNode *temp=new ListNode(pq.top());
prev->next=temp;
prev=temp;
pq.pop();
}
return dumy->next;
}

Comments (0)