File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
src/main/java/com/fishercoder/solutions Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .fishercoder .solutions ;
2
+
3
+ import java .util .HashMap ;
4
+ import java .util .Map ;
5
+
6
+ public class _3164 {
7
+ public static class Solution1 {
8
+ public long numberOfPairs (int [] nums1 , int [] nums2 , int k ) {
9
+ long count = 0 ;
10
+ Map <Integer , Integer > map = new HashMap <>();
11
+ for (int num : nums2 ) {
12
+ int product = num * k ;
13
+ map .put (product , map .getOrDefault (product , 0 ) + 1 );
14
+ }
15
+ for (int num : nums1 ) {
16
+ for (int j = 1 ; j * j <= num ; j ++) {
17
+ if (num % j == 0 ) {
18
+ if (map .containsKey (j )) {
19
+ count += map .get (j );
20
+ }
21
+ int division = num / j ;
22
+ if (j != division && map .containsKey (division )) {
23
+ count += map .get (division );
24
+ }
25
+ }
26
+ }
27
+ }
28
+ return count ;
29
+ }
30
+ }
31
+ }
You can’t perform that action at this time.
0 commit comments