Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required.
For example, Given [[0, 30],[5, 10],[15, 20]], return 2.
Solution
/** * Definition for an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */publicclassSolution {publicintminMeetingRooms(Interval[] intervals) {if (intervals ==null||intervals.length==0) return0;if (intervals.length==1) return1;Arrays.sort(intervals, (a, b) ->a.start-b.start);List<List<Interval>> lists =newArrayList<>();for (int i =0; i <intervals.length; i++) {Interval current = intervals[i];int j =0;for (; j <lists.size(); j++) {if (conflict(current,lists.get(j))) {continue; } else {break; } }if (j !=lists.size()) {lists.get(j).add(current); } else {lists.add(newArrayList<>());lists.get(lists.size() -1).add(current); } }returnlists.size(); }privatebooleanconflict(Interval current,List<Interval> intervals) {if (intervals.isEmpty()) {returnfalse; }Interval last =intervals.get(intervals.size() -1);if (last.end>current.start||current.start==last.start) {returntrue; } else {returnfalse; } }}