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
.
Analysis:
It is the same with Lintcode-max number of airplanes.
Solution:
/*** Definition for a interval. * public class Interval {* int start; * int end; * Interval () {start = 0; end = 0; } * Interval (int s, int e) {start = s; end = e;} }*/ Public classSolution { Public intminmeetingrooms (interval[] intervals) {if(INTERVALS.LENGTH<2)returnintervals.length; HashMap<Integer,Integer> timecounts =NewHashmap<integer,integer>(); for(Interval conf:intervals) {intStartcount = Timecounts.getordefault (conf.start,0) +1; Timecounts.put (Conf.start,startcount); intEndcount = Timecounts.getordefault (conf.end,0)-1; Timecounts.put (Conf.end,endcount); } List<Integer> times =NewArraylist<integer>(); Times.addall (Timecounts.keyset ()); Collections.sort (times); intMaxnum = 0, Curnum = 0; for(inttime:times) { intCount =Timecounts.get (time); Curnum+=count; Maxnum=Math.max (Maxnum,curnum); } returnMaxnum; }}
Leetcode-meeting Rooms II