-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4sum.cc
More file actions
27 lines (24 loc) · 710 Bytes
/
4sum.cc
File metadata and controls
27 lines (24 loc) · 710 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
#include "leetcode.h"
using namespace std;
class Solution {
public:
int fourSumCount(vector<int> &A, vector<int> &B, vector<int> &C, vector<int> &D) {
int counter = 0;
map<int, int> sum_map;
for (const auto a : A) {
for (const auto b : B) { ++sum_map[a + b]; }
}
for (const auto c : C) {
for (const auto d : D) { counter += sum_map[-(c + d)]; }
}
return counter;
}
};
int main(int argc, char const *argv[]) {
Solution solution;
vector<int> a{0, 1, -1};
vector<int> b{-1, 1, 0};
vector<int> c{0, 0, 1};
vector<int> d{-1, 1, 1};
cout << solution.fourSumCount(a, b, c, d) << endl;
}