1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-09-16 16:36:56 +02:00
LeetCode/swift/minimum-number-of-arrows-to-burst-balloons.swift
2024-06-02 15:14:15 +02:00

19 lines
467 B
Swift

class Solution {
func findMinArrowShots(_ points: [[Int]]) -> Int {
let points = points.sorted(by: { a, b in return a[0] < b[0] })
var usedArrows = 1
var maxX = points[0][1]
for point in points.dropFirst() {
if point[0] <= maxX {
maxX = min(maxX, point[1])
} else {
maxX = point[1]
usedArrows += 1
}
}
return usedArrows
}
}