1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-10-18 06:42:08 +02:00
LeetCode/go/check-if-array-pairs-are-divisible-by-k.go
2024-10-01 22:48:13 +02:00

19 lines
346 B
Go

package main
func canArrange(arr []int, k int) bool {
counters := make([]int, k)
for _, x := range arr {
counters[(x%k+k)%k]++
}
for i := 0; i < k && counters[i] != -1; i++ {
j := (k - i) % k
if counters[i] != counters[j] || (i == j && counters[i]%2 == 1) {
return false
}
counters[i], counters[j] = -1, -1
}
return true
}