252. 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.
We can sort the intervals
by the start time, if those intervals have no overlap, then the person could attend all meetings.
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
if (intervals == null || intervals.length == 0) {
return true;
}
Arrays.sort(intervals, (i1, i2) -> {
return i1[0] - i2[0];
});
for (int i = 0; i < intervals.length; i++) {
if (i + 1 < intervals.length && intervals[i][1] > intervals[i + 1][0]) {
return false;
}
}
return true;
}
}