add new solutions
This commit is contained in:
parent
9a10695e8c
commit
ca24d0a56a
30 changed files with 697 additions and 16 deletions
27
solutions/13/q1365/solution.go
Normal file
27
solutions/13/q1365/solution.go
Normal 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
|
||||
Loading…
Add table
Add a link
Reference in a new issue