/** 252.Meeting Rooms * 2016-6-20 by Mingyang * Arrays.sort usage to be familiar with this problem and merge intervals very much like, we press the start time to put these inte Once the rval are sorted, check to see if there is a conflict on the line. * Conflicting definitions are when the start time is less than the latest end time. * The last time before the end is not necessarily the last end time, so we have to take the maximum value when updating. */ Public Booleancanattendmeetings (interval[] intervals) {if(Intervals = =NULL|| Intervals.length = = 0)return true; Arrays.sort (intervals,NewComparator<interval>(){ Public intCompare (Interval i1, Interval i2) {returnI1.start-I2.start; } }); intEnd = Intervals[0].end; //check each of the interval for(inti = 1; i < intervals.length; i++){ //If the start time of the interval is less than the late end time, the return is False if(Intervals[i].start < end)return false; End=Math.max (end, intervals[i].end); } return true; }
252.Meeting Rooms