简简单单优先队列

class Solution {
public:
    struct Node
    {
        int id,val;
        ListNode * p;
        bool operator < (const Node & a) const{
            return val > a.val;
        }
    };

    ListNode * append(int x,ListNode *tail)
    {
        ListNode *tmp = new ListNode(x);
        tail -> next = tmp;
        return tmp;
    }

    ListNode *mergeKLists(vector<ListNode *> &lists) {
        ListNode *head = new ListNode(0),*tail = head;
        priority_queue<Node> pq;
        for(int i=0;i<lists.size();i++) if(lists[i])
            pq.push(Node{i,lists[i] -> val,lists[i]});
        while(!pq.empty())
        {
            Node tmp = pq.top();pq.pop();
            tail = append(tmp.val,tail);
            if(tmp.p -> next)    pq.push(Node{tmp.id,tmp.p->next->val,tmp.p->next});
        }
        return head -> next;
    }
};