LintCode Q 920 - Meeting Rooms
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],…], determine if a person could attend all meetings.
Example1Input: intervals = [(0,30),(5,10),(15,20)] ; Output: false
Explanation:
(0,30), (5,10) and (0,30),(15,20) will conflict
Example2Input: intervals = [(5,8),(9,15)] ; Output: true
Explanation:
Two times will not conflict
Solution
Code:
public boolean canAttendMeetings(List<Interval> intervals) {
if (intervals.size() <= 1) return true;
Collections.sort(intervals, (a,b) -> (a.end - b.end));
int curEnd = intervals.get(0).end;
for (int i = 1; i < intervals.size(); i++) {
Interval interval = intervals.get(i);
if (interval.start < curEnd)
return false;
else
curEnd = interval.end;
}
return true;
}