-
Notifications
You must be signed in to change notification settings - Fork 481
/
0454.cpp
42 lines (41 loc) · 950 Bytes
/
0454.cpp
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
class Solution
{
public:
int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D)
{
unordered_map<int, int> record;
for (auto& i : C)
{
for (auto& j : D)
{
++record[i + j];
}
}
int result = 0;
for (auto& i : A)
{
for (auto& j : B)
{
if (record.count(- i - j))
{
result += record[- i - j];
}
}
}
return result;
}
};
int main()
{
vector<int> A = {1, 2};
vector<int> B = {-2, -1};
vector<int> C = {-1, 2};
vector<int> D = {0, 2};
cout << Solution().fourSumCount(A, B, C, D) << endl;
return 0;
}