add new solutions

This commit is contained in:
kanna5 2026-01-05 16:48:03 +09:00
parent 9a10695e8c
commit ca24d0a56a
Signed by: kkyy
GPG key ID: 06332F3965E9B0CF
30 changed files with 697 additions and 16 deletions

View file

@ -0,0 +1,27 @@
package q1365
import "slices"
func smallerNumbersThanCurrent(nums []int) []int {
buf := make([]int, 2*len(nums))
positions := buf[0:len(nums)]
for i := range positions {
positions[i] = i
}
slices.SortFunc(positions, func(a, b int) int { return nums[a] - nums[b] })
nLesser := buf[len(nums):]
last := -1
for i, p := range positions {
if nums[p] == last {
nLesser[p] = nLesser[positions[i-1]]
} else {
last = nums[p]
nLesser[p] = i
}
}
return nLesser
}
var _ = smallerNumbersThanCurrent