URL: https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ Signed-off-by: Matej Focko <me@mfocko.xyz>
19 lines
432 B
Kotlin
19 lines
432 B
Kotlin
class Solution {
|
|
fun findMinArrowShots(points: Array<IntArray>): Int {
|
|
points.sortBy { it[0] }
|
|
|
|
var usedArrows = 1
|
|
points.drop(1).fold(points[0][1]) { maxX, it ->
|
|
when {
|
|
it[0] <= maxX -> listOf(maxX, it[1]).min()
|
|
else -> {
|
|
usedArrows++
|
|
|
|
it[1]
|
|
}
|
|
}
|
|
}
|
|
|
|
return usedArrows
|
|
}
|
|
}
|