Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcf1de47

Browse files
refactor 253
1 parent81f113f commitcf1de47

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
packagecom.fishercoder.solutions;
22

3-
importcom.fishercoder.common.classes.Interval;
4-
53
importjava.util.Arrays;
64
importjava.util.PriorityQueue;
75

86
publicclass_253 {
97
publicstaticclassSolution1 {
108

11-
publicintminMeetingRooms(Interval[]intervals) {
9+
publicintminMeetingRooms(int[][]intervals) {
1210
if (intervals ==null ||intervals.length ==0) {
1311
return0;
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 =newPriorityQueue<>(intervals.length, (a,b) ->a.end -b.end);
18+
PriorityQueue<int[]>heap =newPriorityQueue<>(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 (inti =1;i <intervals.length;i++) {
2624
// get the meeting room that finishes earliest
27-
Intervalinterval =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)

[8]ページ先頭

©2009-2025 Movatter.jp