File tree 1 file changed +5
-9
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +5
-9
lines changed Original file line number Diff line number Diff line change 5
5
6
6
public class _454 {
7
7
public static class Solution1 {
8
- public int fourSumCount (int [] A , int [] B , int [] C , int [] D ) {
8
+ public int fourSumCount (int [] nums1 , int [] nums2 , int [] nums3 , int [] nums4 ) {
9
9
Map <Integer , Integer > map = new HashMap ();
10
10
int result = 0 ;
11
- int len = A .length ;
11
+ int len = nums1 .length ;
12
12
for (int i = 0 ; i < len ; i ++) {
13
13
for (int j = 0 ; j < len ; j ++) {
14
- int sum = A [i ] + B [j ];
15
- if (map .containsKey (sum )) {
16
- map .put (sum , map .get (sum ) + 1 );
17
- } else {
18
- map .put (sum , 1 );
19
- }
14
+ int sum = nums1 [i ] + nums2 [j ];
15
+ map .put (sum , map .getOrDefault (sum , 0 ) + 1 );
20
16
}
21
17
}
22
18
23
19
for (int i = 0 ; i < len ; i ++) {
24
20
for (int j = 0 ; j < len ; j ++) {
25
- int sum = -(C [i ] + D [j ]);
21
+ int sum = -(nums3 [i ] + nums4 [j ]);
26
22
if (map .containsKey (sum )) {
27
23
result += map .get (sum );
28
24
}
You can’t perform that action at this time.
0 commit comments