Skip to content

Instantly share code, notes, and snippets.

@kanrourou
Created December 21, 2018 06:11
Show Gist options
  • Save kanrourou/962091e6574ee1868159931269c62bd5 to your computer and use it in GitHub Desktop.
Save kanrourou/962091e6574ee1868159931269c62bd5 to your computer and use it in GitHub Desktop.
class Solution {
public:
int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
unordered_map<int, int> map;
int res = 0;
for (int i = 0; i < A.size(); ++i)
{
for (int j = 0; j < B.size(); ++j)
{
int sum = A[i] + B[j];
++map[sum];
}
}
for (int i = 0; i < C.size(); ++i)
{
for (int j = 0; j < D.size(); ++j)
{
int sum = C[i] + D[j];
res += map[-sum];
}
}
return res;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment