[LeetCode 253] 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
.
solution:
put start and negative end into list, sort it based on the absolute value. use two variable to record minimum meeting room
public int minMeetingRooms(Interval[] intervals) {
int res = 0;
if(intervals.length == 0) return res;
if(intervals.length == 1) return res+1;
List<Integer> points = new ArrayList<>();
for(int i=0;i<intervals.length;i++) {
points.add(intervals[i].start);
points.add(-intervals[i].end);
}
Collections.sort(points, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return Math.abs(o1) - Math.abs(o2);
}
});
int local = 0;
for(int i=0;i<points.size();i++) {
if(points.get(i)>=0) {
local++;
}
else local--;
res = Math.max(local, res);
}
return res;
}
相關文章
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- [LeetCode253]Meeting Rooms IILeetCodeOOM
- 253. Meeting Rooms IIOOM
- LeetCode 253. Meeting Rooms II(會議室)LeetCodeOOM
- Leetcode 253:Meeting Rooms II(超詳細的解法!!!)LeetCodeOOM
- [Leetcode] 253. Meeting Rooms II 解題報告LeetCodeOOM
- 【LeetCode】253. Meeting Rooms II 解題報告(C++)LeetCodeOOMC++
- LeetCode-Meeting Rooms IILeetCodeOOM
- *LeetCode-Meeting Rooms IILeetCodeOOM
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- Meeting Rooms IIOOM
- Leetcode 252. Meeting Room 253. Meeting Room IILeetCodeOOM
- Leetcode: Meeting RoomsLeetCodeOOM
- LeetCode #252 - Meeting RoomsLeetCodeOOM
- Leetcode 252 Meeting RoomsLeetCodeOOM
- [LeetCode 252] Meeting RoomsLeetCodeOOM
- Leetcode 253: meeting roomLeetCodeOOM
- LeetCode252 Meeting RoomsLeetCodeOOM
- leetcode-252-Meeting RoomsLeetCodeOOM
- [LintCode/LeetCode] Meeting RoomsLeetCodeOOM
- [LeetCode] Meeting Rooms 會議室LeetCodeOOM
- LeetCode 題解(254) : Meeting RoomsLeetCodeOOM
- Leetcode 252. Meeting Rooms (Easy) (cpp)LeetCodeOOM
- LeetCode 252. Meeting Rooms (Java版; Easy)LeetCodeOOMJava
- LeetCode 252. Meeting Rooms(會議室)LeetCodeOOM
- 252. Meeting RoomsOOM
- [leetcode] 252. Meeting Rooms 解題報告LeetCodeOOM
- leetcode253——會議室 II——java實現LeetCodeJava
- Facebook面試題 meeting rooms 求同時最多meeting room的時間面試題OOM
- LeetCode-Best Meeting PointLeetCode
- Leetcode Meeting room問題系列 - 2LeetCodeOOM
- Leetcode Meeting room問題系列 - 1LeetCodeOOM
- [LeetCode] Jump Game IILeetCodeGAM
- Leetcode jump Game IILeetCodeGAM
- Leetcode Spiral Matrix IILeetCode
- Leetcode Path Sum IILeetCode
- Leetcode-Subsets IILeetCode
- Leetcode-Permutations IILeetCode