Skip to content

Commit cf5a995

Browse files
committed
Runtime: 15 ms (Top 5.12%) | Memory: 43.6 MB (Top 19.49%)
1 parent 49447a0 commit cf5a995

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Runtime: 15 ms (Top 5.12%) | Memory: 43.6 MB (Top 19.49%)
2+
class Solution {
3+
public int countPairs(int[] nums, int k) {
4+
HashMap<Integer,List<Integer>> hMap = new HashMap<>();
5+
int count = 0;
6+
for(int i = 0 ; i < nums.length ; i++){
7+
if(!hMap.containsKey(nums[i])){
8+
List<Integer> l = new ArrayList<>();
9+
l.add(i);
10+
hMap.put(nums[i],l);
11+
}else{
12+
List<Integer> v = hMap.get(nums[i]);
13+
for(Integer j : v){
14+
if((i*j)%k == 0) count++;
15+
}
16+
v.add(i);
17+
hMap.put(nums[i],v);
18+
}
19+
}
20+
return count;
21+
}
22+
}

0 commit comments

Comments
 (0)