kt: add «452. Minimum Number of Arrows to Burst Balloons»
URL: https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/ Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
788199789d
commit
0da1240d26
1 changed files with 19 additions and 0 deletions
19
kt/minimum-number-of-arrows-to-burst-balloons.kt
Normal file
19
kt/minimum-number-of-arrows-to-burst-balloons.kt
Normal file
|
@ -0,0 +1,19 @@
|
|||
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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue