Make intervals a ArrayList and then re-write your own comparator, sort intervals, sort by start time, sort by end time if the start time is the same
Finally, check all the interval, if the previous end time is after the beginning of this one, then return false. If it's done, then it's true.
If the list length is 1, then surely true does not require a separate check
1 Public Booleancanattendmeetings (interval[] intervals) {2List<interval> intervallist =NewArraylist<interval>(Arrays.aslist (intervals));3Collections.sort (Intervallist,NewComparator<interval>() {4 Public intCompare (Interval O1, Interval O2) {5 if(O1.start! =O2.start) {6 returnO1.start-O2.start;7}Else {8 returnO1.end-O2.end;9 }Ten } One }); A for(inti = 1; i < intervals.length; i++) { - if(Intervallist.get (i-1). End >Intervallist.get (i). Start) { - return false; the } - } - return true; -}
252. Meeting Rooms