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;
        }
    }
  • 相关阅读:
    父组件和子组件之间的生命周期执行顺序
    Vue生命周期四个阶段
    Vue watch监听
    Vue computed计算属性 理解
    Vue中v-if 与 v-show的区别
    虚拟DOM
    MVC与MVVM原理
    单例模式 回流与重绘
    判断某个对象属于哪种数据类型
    原生JS的兼容性问题
  • 原文地址:https://www.cnblogs.com/yonezu/p/13361228.html
Copyright © 2011-2022 走看看