zoukankan      html  css  js  c++  java
  • 一个会议室最多安排几场宣讲


    import java.util.Arrays;

    /**
    * 一些项目要占用一个会议室宣讲,会议室不能同时容纳两个项目的宣讲
    * 提供每个项目的开始时间和结束时间,安排,返回最多的宣讲场次
    */
    public class BestArrange {

    public static int bestArrange(Program[] programs) {
    Arrays.sort(programs, (a, b) -> a.end - b.end);
    int timeLine = 0;
    int result = 0;
    for (int i = 0; i < programs.length; i++) {
    if (timeLine <= programs[i].start) {
    result++;
    timeLine = programs[i].end;
    }
    }
    return result;
    }

    /**
    * 项目会议
    */
    public class Program {

    // 开始时间
    public int start;

    // 结束时间
    public int end;

    public Program(int start, int end) {
    this.start = start;
    this.end = end;
    }

    }

    }

    /* 如有意见或建议,欢迎评论区留言;如发现代码有误,欢迎批评指正 */
  • 相关阅读:
    spring加载bean实例化顺序
    Java生成CSV文件实例详解
    JSch
    socket(一)
    Core Data
    运行时c函数
    ReactiveCocoa(RAC)
    先来个xmpp学习连接
    FMDB
    NSKeyedArchive(存储自定义对象)
  • 原文地址:https://www.cnblogs.com/laydown/p/13060844.html
Copyright © 2011-2022 走看看