252. Meeting Rooms

Easy

在一道Easy题上找到了Bug Free的愉悦感, 因为之前做过Merge Intervals和Meeting Rooms ii, 这道题实在是太简单了。

/**
 * 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; }
 * }
 */
class Solution {
    public boolean canAttendMeetings(Interval[] intervals) {
        //[[0, 30],[5, 10],[15, 20]]
        if (intervals == null || intervals.length == 0){
            return true;
        }
        Arrays.sort(intervals, new Comparator<Interval>(){
            public int compare(Interval a, Interval b){
                return a.start - b.start;
            }
        });
        int end = intervals[0].end;
        for (int i = 1; i < intervals.length; i++){
            if (intervals[i].start >= end){
                end = intervals[i].end;
            } else {
                return false;
            }
        }
        return true;
    }
}
    原文作者:greatfulltime
    原文地址: https://www.jianshu.com/p/ace4eea3f907
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞