We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fecbb3d commit 751d783Copy full SHA for 751d783
2277-count-equal-and-divisible-pairs-in-an-array/solution.py
@@ -1,13 +1,17 @@
1
+# Approach 1: Traverse number pairs
2
+
3
+# Time: O(n^2)
4
+# Space: O(1)
5
6
class Solution:
7
def countPairs(self, nums: List[int], k: int) -> int:
8
n = len(nums)
- count = 0
-
- for i in range(n):
- 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):
13
if nums[i] == nums[j] and (i * j) % k == 0:
- count += 1
- return count
14
+ res += 1
15
16
+ return res
17
0 commit comments