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
return
Given
[[0, 30],[5, 10],[15, 20]]
,return
false
.
Solution 1: Sort the interval, make sure there is no overlap.
public class Solution {
class InterComp implements Comparator<Interval> {
@Override
public int compare(Interval a, Interval b) {
return a.start-b.start;
}
}
public boolean canAttendMeetings(Interval[] intervals) {
int n=intervals.length;
Arrays.sort(intervals,new InterComp());
for (int i=1; i<n; i++) {
if (intervals[i].start<intervals[i-1].end) return false;
}
return true;
}
}
没有评论:
发表评论