Skip to content

Commit 46ba87a

Browse files
committed
Added 4Sum II.java
1 parent 2e3e762 commit 46ba87a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Medium/4Sum II.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+
int n = A.length;
4+
Map<Integer, Integer> map = new HashMap<>();
5+
for (int i = 0; i < n; i++) {
6+
for (int j = 0; j < n; j++) {
7+
map.put(A[i] + B[j], map.getOrDefault(A[i] + B[j], 0) + 1);
8+
}
9+
}
10+
int count = 0;
11+
for (int i = 0; i < n; i++) {
12+
for (int j = 0; j < n; j++) {
13+
count += map.getOrDefault(-1 * (C[i] + D[j]), 0);
14+
}
15+
}
16+
return count;
17+
}
18+
}

0 commit comments

Comments
 (0)