Skip to content

Commit cf1de47

Browse files
refactor 253
1 parent 81f113f commit cf1de47

File tree

1 file changed

+6
-8
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+6
-8
lines changed

src/main/java/com/fishercoder/solutions/_253.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
package com.fishercoder.solutions;
22

3-
import com.fishercoder.common.classes.Interval;
4-
53
import java.util.Arrays;
64
import java.util.PriorityQueue;
75

86
public class _253 {
97
public static class Solution1 {
108

11-
public int minMeetingRooms(Interval[] intervals) {
9+
public int minMeetingRooms(int[][] intervals) {
1210
if (intervals == null || intervals.length == 0) {
1311
return 0;
1412
}
1513

1614
// Sort the intervals by start time
17-
Arrays.sort(intervals, (a, b) -> a.start - b.start);
15+
Arrays.sort(intervals, (a, b) -> a[0] - b[0]);
1816

1917
// Use a min heap to track the minimum end time of merged intervals
20-
PriorityQueue<Interval> heap = new PriorityQueue<>(intervals.length, (a, b) -> a.end - b.end);
18+
PriorityQueue<int[]> heap = new PriorityQueue<>(intervals.length, (a, b) -> a[1] - b[1]);
2119

2220
// start with the first meeting, put it to a meeting room
2321
heap.offer(intervals[0]);
2422

2523
for (int i = 1; i < intervals.length; i++) {
2624
// get the meeting room that finishes earliest
27-
Interval interval = heap.poll();
25+
int[] interval = heap.poll();
2826

29-
if (intervals[i].start >= interval.end) {
27+
if (intervals[i][0] >= interval[1]) {
3028
// if the current meeting starts right after
3129
// there's no need for a new room, merge the interval
32-
interval.end = intervals[i].end;
30+
interval[1] = intervals[i][1];
3331
} else {
3432
// otherwise, this meeting needs a new room
3533
heap.offer(intervals[i]);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy