zoukankan      html  css  js  c++  java
  • LeetCode


    /**
     * Definition for singly-linked list.
     * struct ListNode {
     *     int val;
     *     ListNode *next;
     *     ListNode(int x) : val(x), next(NULL) {}
     * };
     */

    class Solution {

    public:
        struct compare {
        bool operator()(const ListNode* l, const ListNode* r) {
            return l->val > r->val;
        }
    };
    ListNode *mergeKLists(vector<ListNode *> &lists) { //priority_queue
        priority_queue<ListNode *, vector<ListNode *>, compare> key;
        for(int i = 0 ; i < lists.size() ; i ++){
                if(lists[i])
                    key.push(lists[i]);
            }
            ListNode *head = new ListNode(0);
            ListNode *p = head;
            while(!(key.empty())){
                ListNode *fc = key.top();
                if(fc->next)
                    key.push(fc->next);
                p->next = fc;
                p = fc;
                key.pop();
            }
        return head->next;
        }
    };

  • 相关阅读:
    (转载)关于一些对location认识的误区
    Python内置数据结构--列表
    Maven
    Python基础语法
    安装ipython和jupyter
    Python环境安装
    Java多线程
    SpringMVC集成springfox-swagger2自动生成接口文档
    SpringMVC拦截器
    SpringMVC异常处理器
  • 原文地址:https://www.cnblogs.com/clover-xuqi/p/7182376.html
Copyright © 2011-2022 走看看