原题链接在这里:https://leetcode.com/problems/meeting-rooms/

题目:

Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.

For example,
Given [[0, 30],[5, 10],[15, 20]],
return false.

题解:

对array进行排序,从i = 1开始判断start是否在前一个end之前, 若是就return false. 完成loop返回true.

Time Complexity: O(nlogn). Space: O(1).

AC Java:

 /**
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
public class Solution {
public boolean canAttendMeetings(Interval[] intervals) {
if(intervals == null || intervals.length == 0){
return true;
}
Arrays.sort(intervals, new Comparator<Interval>(){
public int compare(Interval i1, Interval i2){
if(i1.start == i2.start){
return i1.end - i2.end;
}
return i1.start - i2.start;
}
}); for(int i = 1; i<intervals.length; i++){
if(intervals[i].start < intervals[i-1].end){
return false;
}
}
return true;
}
}

跟上Meeting Rooms II

LeetCode Meeting Rooms的更多相关文章

  1. [LeetCode] Meeting Rooms II 会议室之二

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  2. [LeetCode] Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  3. LeetCode Meeting Rooms II

    原题链接在这里:https://leetcode.com/problems/meeting-rooms-ii/ Given an array of meeting time intervals con ...

  4. [LeetCode] Meeting Rooms I & II

    Meeting Rooms Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s ...

  5. [LeetCode] 253. Meeting Rooms II 会议室之二

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  6. [LeetCode] 252. Meeting Rooms 会议室

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  7. [LeetCode] 253. Meeting Rooms II 会议室 II

    Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si ...

  8. [Algorithm] How many meeting rooms needed?

    Give you set of meetings start time and end time, count how many meeting rooms needed. For example: ...

  9. 252. Meeting Rooms 区间会议室

    [抄题]: Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],.. ...

随机推荐

  1. erlang-jiffy 安装手记

    今天安装 erlang-jiffy 把握逼疯,不过最后还是成功了. 错误避免: rebar只能再英文目录下运行,如果编译jiffy的目录中有中文或其它unicode字符,将会出错 从git relea ...

  2. java操作FTP,实现文件上传下载删除操作

    上传文件到FTP服务器: /** * Description: 向FTP服务器上传文件 * @param url FTP服务器hostname * @param port FTP服务器端口,如果默认端 ...

  3. php 版本的indexof —— strpos坑爹

    如果没有找到则会返回false,如果是在第一位,那么会返回0.那么在if判断的时候会非常麻烦. 我的方法是转化为string,当返回0的时候则是"0",如果返回的是false,则会 ...

  4. 文件上传\">将在3秒钟后返回前页

    conn.php: <?php $id=mysql_connect('localhost','root','root'); mysql_select_db("db_database12 ...

  5. php一些技巧函数

    current() next() prev() 范例 <?php $people = array("Peter", "Joe", "Glenn& ...

  6. 利用SpannableString设置文本

    private void setTips(){ String big = "大字深色"; String small = "小字淡色"; Spannable ti ...

  7. Ubuntu中搭建Nginx+PHP环境最简单的方法

    先安装: sudo apt-get install nginx php5-fpm 然后编辑配置文件: sudo gedit /etc/nginx/site-available/default 找到lo ...

  8. Flink - Generating Timestamps / Watermarks

    https://ci.apache.org/projects/flink/flink-docs-release-1.0/apis/streaming/event_timestamps_watermar ...

  9. url如何传递参数

    $(document).ready(function() { var name=getQueryString('minename'); if (name != null && name ...

  10. PureBasic—数控编辑框与调节块和进度条

    三个有关上下限问题的控件,它们也是主要控件的组成部分,分别为:SpinGadget()        数控编辑框TrackBarGadget()    调节块控件ProgressBarGadget() ...