Skip to content

Commit ae3fa73

Browse files
committed
refactor: add Kotlin solution for 253. Meeting Rooms II
1 parent d64e544 commit ae3fa73

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

kotlin/0253-meeting-rooms-ii.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
fun minMeetingRooms(intervals: Array<IntArray>): Int {
3+
val startTimes = intervals.map { it.first() }.sorted()
4+
val endTimes = intervals.map { it.last() }.sorted()
5+
var (startIndex, endIndex) = Pair(0, 0)
6+
var minMeetingRooms = 0
7+
while (startIndex in startTimes.indices) {
8+
if (startTimes[startIndex] < endTimes[endIndex]) {
9+
minMeetingRooms++
10+
startIndex++
11+
} else {
12+
startIndex++
13+
endIndex++
14+
}
15+
}
16+
return minMeetingRooms
17+
}
18+
}

0 commit comments

Comments
 (0)