leetcode253. 会议室 II
生活随笔
收集整理的這篇文章主要介紹了
leetcode253. 会议室 II
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
給定一個會議時間安排的數組,每個會議時間都會包括開始和結束的時間 [[s1,e1],[s2,e2],...] (si < ei),為避免會議沖突,同時要考慮充分利用會議室資源,請你計算至少需要多少間會議室,才能滿足這些會議安排。
示例 1:
輸入: [[0, 30],[5, 10],[15, 20]]
輸出: 2
示例 2:
輸入: [[7,10],[2,4]]
輸出: 1
思路:所有時間點一塊操作:遇到會議開始+1,遇到會議結束-1,統計最大值即可,無需關心具體是哪個會議開始和結束。
class Solution {public int minMeetingRooms(int[][] intervals) {if(intervals == null || intervals.length == 0) return 0; int[] start = new int[intervals.length];int[] end = new int[intervals.length];for(int i=0;i<intervals.length;i++){start[i] = intervals[i][0];end[i] = intervals[i][1];}Arrays.sort(start);Arrays.sort(end);int rooms=0, activeMeeting = 0;int i=0,j=0;while(i<intervals.length && j<intervals.length){if(start[i]<end[j]){activeMeeting++;i++;}else{activeMeeting--;j++;}rooms = Math.max(rooms,activeMeeting);}return rooms;} }?
總結
以上是生活随笔為你收集整理的leetcode253. 会议室 II的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Unity客户端开发优化要点
- 下一篇: 二分查找及一般拓展总结