add new solutions
This commit is contained in:
parent
886b5e0a8e
commit
67cad91898
47 changed files with 1549 additions and 1 deletions
32
solutions/23/q2300/solution.go
Normal file
32
solutions/23/q2300/solution.go
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package q2300
|
||||
|
||||
import "slices"
|
||||
|
||||
func nGte(arr []int, target int) int {
|
||||
l, r := 0, len(arr)
|
||||
for l < r {
|
||||
m := (l + r) / 2
|
||||
if arr[m] >= target {
|
||||
r = m
|
||||
} else {
|
||||
l = m + 1
|
||||
}
|
||||
}
|
||||
return len(arr) - l
|
||||
}
|
||||
|
||||
func successfulPairs(spells []int, potions []int, success int64) []int {
|
||||
slices.Sort(potions)
|
||||
|
||||
for i := range spells {
|
||||
pow := spells[i]
|
||||
want := int(success) / pow
|
||||
if pow*want < int(success) {
|
||||
want++
|
||||
}
|
||||
spells[i] = nGte(potions, want)
|
||||
}
|
||||
return spells
|
||||
}
|
||||
|
||||
var _ = successfulPairs
|
||||
Loading…
Add table
Add a link
Reference in a new issue