Created
December 21, 2018 06:11
-
-
Save kanrourou/962091e6574ee1868159931269c62bd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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