MrainW's Home

All things come to those who wait!

0%

LeetCode 253. Meeting Rooms II

Question

Given an array of meeting time intervals intervals where intervals[i] = [starti, endi], return the minimum number of conference rooms required.

https://leetcode.com/problems/meeting-rooms-ii/

  • Solution1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution {
public int minMeetingRooms(int[][] intervals) {
int res = 0;
List<int[]> list = new ArrayList<>();
for (int[] interval : intervals){
list.add(new int[]{interval[0], 1});
list.add(new int[]{interval[1], -1});
}
Collections.sort(list, (a, b) -> a[0] == b[0] ? a[1] - b[1] : a[0] -b[0]);
int count =0;
for (int[] point: list){
count += point[1];
res = Math.max(res, count);
}
return res;
}
}

Complexity:

Time complexity: O( nlogn)

Space complexity: O(n)

Welcome to my other publishing channels