Leetcode-meeting Rooms II

Source: Internet
Author: User

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&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.