2277. Count Equal and Divisible Pairs in an Array
My accepted Python solution to LeetCode problem 2277, Count Equal and Divisible Pairs in an Array, running in 35ms.
- Difficulty: Easy
- Python
- Runtime 35ms
- Memory 12.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 35ms, memory 12.3MB, accepted 2025-12-24.
class Solution(object):
def countPairs(self, nums, k):
count = 0
n = len(nums)
for i in range(n):
for j in range(i + 1, n):
if nums[i] == nums[j] and (i * j) % k == 0:
count += 1
return count