The original title link is here: https://leetcode.com/problems/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.
For example,
Given [[0, 30],[5, 10],[15, 20]]
,
Return false
.
Sorts the array, starting from i = 2 to determine if start is before the previous end, and if so, return false. Complete loop returns TRUE.
Time Complexity:o (NLOGN). Space:o (1).
AC Java:
1 /**2 * Definition for an interval.3 * public class Interval {4 * int start;5 * int end;6 * Interval () {start = 0; end = 0;}7 * Interval (int s, int e) {start = s; end = e;}8 * }9 */Ten Public classSolution { One Public Booleancanattendmeetings (interval[] intervals) { A if(Intervals = =NULL|| Intervals.length = = 0){ - return true; - } theArrays.sort (intervals,NewComparator<interval>(){ - Public intCompare (Interval i1, Interval i2) { - if(I1.start = =I2.start) { - returnI1.end-I2.end; + } - returnI1.start-I2.start; + } A }); at - for(inti = 1; i<intervals.length; i++){ - if(Intervals[i].start < Intervals[i-1].end) { - return false; - } - } in return true; - } to}
Meet Meeting Rooms II
Leetcode Meeting Rooms