mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-30 22:48:43 +01:00
20201230
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func process(nums []int) []int {
|
||||
var ret []int
|
||||
c := 0
|
||||
for {
|
||||
if len(ret) == len(nums) {
|
||||
break
|
||||
}
|
||||
n := findNextLarge(c, nums)
|
||||
ret = append(ret, n)
|
||||
c++
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func findNextLarge(index int, nums []int) int {
|
||||
if index > len(nums)-1 {
|
||||
return -1
|
||||
}
|
||||
src := append(nums[index+1:], nums[:index+1]...)
|
||||
for i, c := range src {
|
||||
if c > nums[index] {
|
||||
x := index + i + 1
|
||||
if x > len(nums) {
|
||||
x -= len(nums)
|
||||
}
|
||||
return c
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
Reference in New Issue
Block a user