首页 > 代码库 > LeetCode-Meeting Rooms II
LeetCode-Meeting Rooms II
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 an interval. * public class Interval { * int start; * int end; * Interval() { start = 0; end = 0; } * Interval(int s, int e) { start = s; end = e; } * } */public class Solution { public int minMeetingRooms(Interval[] intervals) { if (intervals.length<2) return intervals.length; HashMap<Integer,Integer> timeCounts = new HashMap<Integer,Integer>(); for (Interval conf : intervals){ int startCount = timeCounts.getOrDefault(conf.start,0)+1; timeCounts.put(conf.start,startCount); int endCount = timeCounts.getOrDefault(conf.end,0)-1; timeCounts.put(conf.end,endCount); } List<Integer> times = new ArrayList<Integer>(); times.addAll(timeCounts.keySet()); Collections.sort(times); int maxNum = 0, curNum = 0; for (int time : times){ int count = timeCounts.get(time); curNum += count; maxNum = Math.max(maxNum,curNum); } return maxNum; }}
LeetCode-Meeting Rooms II
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。