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
.
思路:標準掃描線演算法,start event + 1, end event -1, 把所有的event點按照時間sort一下,如果時間相同,-1排在1前面,O(NlogN) + O(N).
class Solution {
private class Node {
public int time;
public int flag;
public Node(int time, int flag) {
this.time = time;
this.flag = flag;
}
}
public int minMeetingRooms(int[][] intervals) {
if(intervals == null || intervals.length == 0 || intervals[0].length == 0) {
return 0;
}
List<Node> list = new ArrayList<Node>();
for(int i = 0; i < intervals.length; i++) {
list.add(new Node(intervals[i][0], 1));
list.add(new Node(intervals[i][1], -1));
}
Collections.sort(list, (a, b) -> (
a.time != b.time ? a.time - b.time : a.flag - b.flag));
int count = 0;
int maxcount = 0;
for(int i = 0; i < list.size(); i++) {
Node node = list.get(i);
if(node.flag == 1) {
count++;
} else {
count--;
}
maxcount = Math.max(maxcount, count);
}
return maxcount;
}
}
相關文章
- 253. Meeting Rooms IIOOM
- LeetCode-Meeting Rooms IILeetCodeOOM
- [LeetCode 253] Meeting Rooms IILeetCodeOOM
- *LeetCode-Meeting Rooms IILeetCodeOOM
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- [LeetCode253]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
- [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
- Daily Stand-up Meeting的反饋AI
- NetMeeting高階應用 (轉)
- Hackable: II
- Leetcode Meeting room問題系列 - 2LeetCodeOOM