Skip to content

Commit 751d783

Browse files
committed
Sync LeetCode submission Runtime - 23 ms (49.67%), Memory - 17.8 MB (80.50%)
1 parent fecbb3d commit 751d783

File tree

1 file changed

+12
-8
lines changed
  • 2277-count-equal-and-divisible-pairs-in-an-array

1 file changed

+12
-8
lines changed
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1+
# Approach 1: Traverse number pairs
2+
3+
# Time: O(n^2)
4+
# Space: O(1)
5+
16
class Solution:
27
def countPairs(self, nums: List[int], k: int) -> int:
38
n = len(nums)
4-
count = 0
5-
6-
for i in range(n):
7-
for j in range(i+1, n):
9+
res = 0
10+
11+
for i in range(n - 1):
12+
for j in range(i + 1, n):
813
if nums[i] == nums[j] and (i * j) % k == 0:
9-
count += 1
10-
11-
return count
12-
14+
res += 1
15+
16+
return res
1317

0 commit comments

Comments
 (0)