Skip to content

Commit bcd4e8e

Browse files
authored
Added Tuple With Same Product.java
1 parent d5a4396 commit bcd4e8e

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

Medium/Tuple With Same Product.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class Solution {
2+
public int tupleSameProduct(int[] nums) {
3+
int count = 0;
4+
Map<Integer, Integer> map = new HashMap<>();
5+
for (int i = 0; i < nums.length; i++) {
6+
for (int j = i + 1; j < nums.length; j++) {
7+
int prod = nums[i] * nums[j];
8+
count += map.getOrDefault(prod, 0);
9+
map.put(prod, map.getOrDefault(prod, 0) + 1);
10+
}
11+
}
12+
return count * 8;
13+
}
14+
}

0 commit comments

Comments
 (0)