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;
        }
    }
  • 相关阅读:
    小小的学习FPGA建议
    不厌其烦的四大集成电路
    关于FPGA复位的认识
    FPGA与图像处理
    谈谈对zynq的浅显理解
    嵌入ARM硬核的FPGA
    FPGA时序约束一点总结
    FPGA时序优化简单窍门
    学习FPGA,踏上一步台阶
    使用poi读取word2007(.docx)中的复杂表格
  • 原文地址:https://www.cnblogs.com/yonezu/p/13361228.html
Copyright © 2011-2022 走看看