add new solutions
This commit is contained in:
parent
9c2c959a9b
commit
9a10695e8c
29 changed files with 1074 additions and 2 deletions
23
solutions/4/q452/solution.go
Normal file
23
solutions/4/q452/solution.go
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package q452
|
||||
|
||||
import "slices"
|
||||
|
||||
func findMinArrowShots(points [][]int) int {
|
||||
slices.SortFunc(points, func(a, b []int) int { return a[0] - b[0] })
|
||||
arrows := 1
|
||||
prev := points[0]
|
||||
|
||||
for i := 1; i < len(points); i++ {
|
||||
cur := points[i]
|
||||
if cur[0] > prev[1] {
|
||||
arrows++
|
||||
prev = cur
|
||||
continue
|
||||
}
|
||||
prev[0] = max(prev[0], cur[0])
|
||||
prev[1] = min(prev[1], cur[1])
|
||||
}
|
||||
return arrows
|
||||
}
|
||||
|
||||
var _ = findMinArrowShots
|
||||
Loading…
Add table
Add a link
Reference in a new issue