1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public static int minMeetingRooms(int[][] intervals) { List<int[]> flat = new ArrayList<>();
for (int[] interval: intervals){ int[] start = {interval[0], 1}; int[] end = {interval[1], -1}; flat.add(start); flat.add(end); }
flat.sort((o1, o2) -> o1[0] == o2[0]? o1[1]-o2[1]: o1[0]-o2[0]);
int result = 0; int count = 0;
while (!flat.isEmpty()) { count += flat.remove(0)[1]; result = Math.max(count, result); }
return result; }
|