mirror of
https://github.com/cubixle/codekata-golang.git
synced 2026-04-24 23:04:42 +01:00
20201204
This commit is contained in:
37
20201204/main.go
Normal file
37
20201204/main.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
||||
|
||||
func countMove(nums []int) int {
|
||||
count := 0
|
||||
l := len(nums)
|
||||
for {
|
||||
if isAllSame(nums) {
|
||||
return count
|
||||
}
|
||||
sort.Ints(nums)
|
||||
for i := 0; i < l-1; i++ {
|
||||
nums[i] += 1
|
||||
}
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
func isAllSame(nums []int) bool {
|
||||
if len(nums) == 0 {
|
||||
return false
|
||||
}
|
||||
base := nums[0]
|
||||
for _, n := range nums {
|
||||
if base != n {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user