-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4Sum II.cs
More file actions
27 lines (25 loc) · 725 Bytes
/
4Sum II.cs
File metadata and controls
27 lines (25 loc) · 725 Bytes
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
public class Solution {
public int FourSumCount(int[] A, int[] B, int[] C, int[] D) {
var map = new Dictionary<int, int>();
foreach (var a in A) {
foreach (var b in B) {
var temp = a + b;
if (map.ContainsKey(temp)) {
++map[temp];
} else {
map[temp] = 1;
}
}
}
var res = 0;
foreach (var c in C) {
foreach (var d in D) {
var target = -1 * (c + d);
if (map.ContainsKey(target)) {
res += map[target];
}
}
}
return res;
}
}