*LeetCode-Meeting Rooms II
首先interval陣列按照start 排序 然後建立一個以end排序的priority queue 這樣每次按照start的先後順序入隊,入隊之前要把所有在這個start之前都結束的會議poll出來
每次更新room數量
public class Solution {
public int minMeetingRooms(Interval[] intervals) {
Arrays.sort ( intervals, new Comparator<Interval>(){
public int compare ( Interval int1, Interval int2 ){
return int1.start - int2.start;
}
});
PriorityQueue <Interval> que = new PriorityQueue<Interval>( new Comparator<Interval>(){
public int compare ( Interval int1, Interval int2 ){
return int1.end - int2.end;
}
});
int rooms = 0;
for ( int i = 0; i < intervals.length; i ++ ){
while ( !que.isEmpty() && que.peek().end <= intervals[ i ].start ){
que.poll();
}
que.offer ( intervals[ i ] );
rooms = Math.max ( rooms, que.size() );
}
return rooms;
}
}
相關文章
- LeetCode-Meeting Rooms IILeetCodeOOM
- Meeting Rooms IIOOM
- 253. Meeting Rooms IIOOM
- [LeetCode 253] 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
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- 【LeetCode】253. Meeting Rooms II 解題報告(C++)LeetCodeOOMC++
- 252. Meeting RoomsOOM
- 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
- Range Addition II 範圍求和 II
- Leetcode 252. Meeting Rooms (Easy) (cpp)LeetCodeOOM
- Hackable: II
- LeetCode 252. Meeting Rooms (Java版; Easy)LeetCodeOOMJava
- LeetCode 252. Meeting Rooms(會議室)LeetCodeOOM
- 黑客字典II黑客
- Reflective Journal II
- Bracket Sequences IIRacket
- (原創) 如何破解Quartus II 7.2 SP1? (IC Design) (Quartus II) (Nios II)iOS
- [leetcode] 252. Meeting Rooms 解題報告LeetCodeOOM
- 【機器學習】梯度下降 II機器學習梯度
- USACO GCD Extreme(II)GCREM
- 設計模式II設計模式
- Collecting Numbers II
- HDU 3625 Examining the Rooms:第一類Stirling數OOM
- 字串的調整II字串
- Chapter III What Is Truth IIAPT