Skip to content

Commit fe581c7

Browse files
authored
Update find-the-number-of-good-pairs-i.cpp
1 parent bc5831d commit fe581c7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

C++/find-the-number-of-good-pairs-i.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ class Solution {
2222
return result;
2323
}
2424
};
25+
26+
// Time: O(n^2)
27+
// Space: O(1)
28+
// brute force
29+
class Solution2 {
30+
public:
31+
int numberOfPairs(vector<int>& nums1, vector<int>& nums2, int k) {
32+
int result = 0;
33+
for (const auto& x : nums1) {
34+
for (const auto& y : nums2) {
35+
if (x % (k * y) == 0) {
36+
++result;
37+
}
38+
}
39+
}
40+
return result;
41+
}
42+
};

0 commit comments

Comments
 (0)