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 [[0, 30],[5, 10],[15, 20]], return false.
O(nlogn).
1 2 3 4 5 6 7 8 9 10
publicclassSolution{ publicbooleancanAttendMeetings(Interval[] intervals){ // Sort the intervals by start time Arrays.sort(intervals, (x, y) -> x.start - y.start); for (int i = 1; i < intervals.length; i++) if (intervals[i-1].end > intervals[i].start) returnfalse; returntrue; } }
The following solution is cited from Leetcode Discussion board.