Leetcode Note: Go - Count Equal and Divisible Pairs in an Array
Count Equal and Divisible Pairs in an Array - LeetCode
https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/
- Go 言語で取り組んだメモ
回答
Count Equal and Divisible Pairs in an Array - LeetCode
https://leetcode.com/problems/count-equal-and-divisible-pairs-in-an-array/solutions/2133880/go-o-n-2-solution/
func countPairs(nums []int, k int) int {
var res int
for i := 0; i < len(nums); i++ {
for j := i + 1; j < len(nums); j++ {
if nums[i] == nums[j] && (i*j) % k == 0 {
res++
}
}
}
return res
}