Skip to content

Commit 3475c00

Browse files
authored
Create Solution.java
1 parent 21b4ce2 commit 3475c00

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

solution/0454.4Sum II/Solution.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public int fourSumCount(int[] A, int[] B, int[] C, int[] D) {
3+
Map<Integer, Integer> map = new HashMap<>();
4+
for (int a : A) {
5+
for (int b : B) {
6+
int key = a + b;
7+
map.put(key, map.getOrDefault(key, 0) + 1);
8+
}
9+
}
10+
int res = 0;
11+
for (int c : C) {
12+
for (int d : D) {
13+
res += map.getOrDefault(-(c + d), 0);
14+
}
15+
}
16+
return res;
17+
}
18+
}

0 commit comments

Comments
 (0)