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;
        }
    }
  • 相关阅读:
    Asp.net操作Excel----NPOI
    Python第一模块
    Sping笔记一览
    IO流技术一览
    事务技术一览
    日常问题记录
    分页与JDBC显示文档。
    分页技术与JDBC一览
    JDBC 技术开发
    MYSQL
  • 原文地址:https://www.cnblogs.com/yonezu/p/13361228.html
Copyright © 2011-2022 走看看