[LeetCode253]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.
Hide Company Tags Google Facebook
Hide Tags Heap Greedy Sort
Hide Similar Problems (H) Merge Intervals (E) Meeting Rooms
這題剛開始想著用個stack按照上一個結束時間和當前開始時間的關係in, out。不對。
看了大家的解法。 用map儲存所有start end point,並且++mp[start], –mp[end]. 因為map 是ordered的, 最後traverse 所有elements in map 求room += m.second. 這樣做就可以知道最大重疊meeting的個數,也就可以求出我們到底最少需要多少meeting room。
class Solution {
public:
int minMeetingRooms(vector<Interval>& intervals) {
if(intervals.empty()) return 0;
map<int, int> mp;
for(Interval i : intervals){
++mp[i.start];
--mp[i.end];
}
int room = 0, maxRoom = INT_MIN;
for(auto m : mp){
maxRoom = max(maxRoom, room += m.second);
}
return maxRoom;
}
};
相關文章
- Meeting Rooms IIOOM
- 253. Meeting Rooms IIOOM
- LeetCode-Meeting Rooms IILeetCodeOOM
- [LeetCode 253] Meeting Rooms IILeetCodeOOM
- *LeetCode-Meeting Rooms IILeetCodeOOM
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- LeetCode 253. Meeting Rooms II(會議室)LeetCodeOOM
- Leetcode 253:Meeting Rooms II(超詳細的解法!!!)LeetCodeOOM
- [Leetcode] 253. Meeting Rooms II 解題報告LeetCodeOOM
- 252. Meeting RoomsOOM
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- 【LeetCode】253. Meeting Rooms II 解題報告(C++)LeetCodeOOMC++
- Leetcode: Meeting RoomsLeetCodeOOM
- LeetCode #252 - Meeting RoomsLeetCodeOOM
- Leetcode 252 Meeting RoomsLeetCodeOOM
- [LeetCode 252] Meeting RoomsLeetCodeOOM
- LeetCode252 Meeting RoomsLeetCodeOOM
- leetcode-252-Meeting RoomsLeetCodeOOM
- [LintCode/LeetCode] Meeting RoomsLeetCodeOOM
- [LeetCode] Meeting Rooms 會議室LeetCodeOOM
- LeetCode 題解(254) : Meeting RoomsLeetCodeOOM
- Facebook面試題 meeting rooms 求同時最多meeting room的時間面試題OOM
- Leetcode 252. Meeting Rooms (Easy) (cpp)LeetCodeOOM
- LeetCode 252. Meeting Rooms (Java版; Easy)LeetCodeOOMJava
- LeetCode 252. Meeting Rooms(會議室)LeetCodeOOM
- leetcode253——會議室 II——java實現LeetCodeJava
- [leetcode] 252. Meeting Rooms 解題報告LeetCodeOOM
- Leetcode 252. Meeting Room 253. Meeting Room IILeetCodeOOM
- OUTLOOK - Unable to Delete Meetingsdelete
- Leetcode 253: meeting roomLeetCodeOOM
- netmeeting命令conf
- LeetCode-Best Meeting PointLeetCode
- AICreateMeeting-遇見未來AI
- Netmeeting 安裝步驟
- Range Addition II 範圍求和 II
- Hackable: II
- Daily Stand-up Meeting的反饋AI
- NetMeeting高階應用 (轉)