BiruLyu
7/26/2017 - 9:30 PM

## 252. Meeting Rooms(#).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) {
int len = intervals.length;
int[] a = new int[len];
int[] b = new int[len];

for (int i = 0; i < len; i++) {
a[i] = intervals[i].start;
b[i] = intervals[i].end;
}

Arrays.sort(a); Arrays.sort(b);

for (int i = 0; i < len - 1; i++) {
if (b[i] > a[i+1]) return false;
}
return true;
}
}``````
``````/**
* 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 < 2) return true;
int len = intervals.length;
Arrays.sort(intervals, new Comparator<Interval>(){
public int compare(Interval a, Interval b) {
return a.start - b.start;
}
});
for (int i = 1; i < len; i++) {
if (intervals[i].start < intervals[i - 1].end) return false;
}
return true;
}
}``````