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

Commit999bb5b

Browse files
authored
Create 2402-meeting-rooms-iii.kt
1 parent03eac5d commit999bb5b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

‎kotlin/2402-meeting-rooms-iii.kt

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
classSolution {
2+
funmostBooked(n:Int,meetings:Array<IntArray>):Int {
3+
meetings.sortBy { it[0] }
4+
5+
val available=PriorityQueue<Int> ().apply {
6+
for (iin0 until n)
7+
add(i)
8+
}
9+
10+
val used=PriorityQueue<Pair<Int,Int>> { a, b->
11+
if (a.first== b.first) a.second- b.second
12+
else a.first- b.first
13+
}
14+
15+
val count=IntArray (n)
16+
17+
for (meetin meetings) {
18+
var (start, end)= meet
19+
while (used.isNotEmpty()&& start>= used.peek().first) {
20+
val (_, room)= used.poll()
21+
available.add(room)
22+
}
23+
24+
if (available.isEmpty()) {
25+
val (endTime, room)= used.poll()
26+
end= endTime+ (end- start)
27+
available.add(room)
28+
}
29+
30+
val room= available.poll()
31+
used.add(end to room)
32+
count[room]++
33+
}
34+
35+
return count.indexOfFirst({ it== (count.max()?:0) })
36+
}
37+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp