- Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy path_1577.java
31 lines (28 loc) · 923 Bytes
/
_1577.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
packagecom.fishercoder.solutions.secondthousand;
importjava.util.HashMap;
importjava.util.Map;
publicclass_1577 {
publicstaticclassSolution1 {
publicintnumTriplets(int[] nums1, int[] nums2) {
longresult = 0;
for (longnum : nums1) {
result += twoProduct(num * num, nums2);
}
for (longnum : nums2) {
result += twoProduct(num * num, nums1);
}
return (int) result;
}
privatelongtwoProduct(longproduct, int[] nums) {
Map<Long, Long> map = newHashMap<>();
longcount = 0;
for (longnum : nums) {
if (product % num == 0) {
count += map.getOrDefault(product / num, 0L);
}
map.put(num, map.getOrDefault(num, 0L) + 1);
}
returncount;
}
}
}