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;
}
}