zoukankan      html  css  js  c++  java
  • 1353. 最多可以参加的会议数目

     

    class Solution {
        public int maxEvents(int[][] events) {
            Arrays.sort(events, Comparator.comparingInt(o -> o[0]));
            PriorityQueue<Integer> queue = new PriorityQueue<>();
            int i = 0;
            int day = 1;
            int res = 0;
            while (i < events.length || !queue.isEmpty()) {
                // 将day天能参加的会议全部加入到优先队列,按照结束时间排序
                while (i < events.length && events[i][0] == day) {
                    queue.add(events[i][1]);
                    i++;
                }
                // 将已经结束的会议全部删掉
                while (!queue.isEmpty() && queue.peek() < day) {
                    queue.poll();
                }
                // 一天只能参加一场会议将结束时间最早的安排了
                if (!queue.isEmpty()) {
                    queue.poll();
                    res++;
                }
                // 安排下一天
                day++;
            }
            return res;
        }
    }
    class Solution {
        public int maxEvents(int[][] events) {
            PriorityQueue<Integer> queue = new PriorityQueue<Integer>();
            Arrays.sort(events,(o1,o2)->o1[0]-o2[0]);
            int i = 0, res = 0, n = events.length;
            for (int d = 1; d <= 100000; ++d) {
                while (i < n && events[i][0] == d){
                    queue.offer(events[i++][1]);
                }
                while (queue.size() > 0 && queue.peek() < d){
                    queue.poll();
                }
                if (queue.size() > 0) {
                    queue.poll();
                    res++;
                }
            }
            return res;
        }
    }
  • 相关阅读:
    ASA5505升级license
    Elasticsearch-URL查询实例解析
    awk和sed
    ftp无法上传问题
    linux使用storcli64查看硬盘信息
    Centos7中kubernetes-1.11.2基于配置亲和与反亲和
    Centos7使用kubeadm部署kubernetes-1.11.2
    内网映射3种方法
    centos6.5使用LVM
    centos7部署openstack-ocata
  • 原文地址:https://www.cnblogs.com/yonezu/p/13361228.html
Copyright © 2011-2022 走看看