• API
• FAQ
• Tools
• Archive
SHARE
TWEET Untitled a guest Mar 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. class Solution {
2. public:
3.     int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
4.         unordered_map <int, int> mp; // 哈希表：A中一个元素加B中一个元素的和的计数
5.         int cnt = 0;
6.         for(int i = 0; i < A.size(); i++) {
7.             for(int j = 0; j < B.size(); j++) {
8.                 int sum = A[i] + B[j];
9.                 mp[sum]++;
10.             }
11.         }
12.
13.         for(int i = 0; i < C.size(); i++) {
14.             for(int j = 0; j < D.size(); j++) {
15.                 int sum = C[i] + D[j];
16.                 if(mp.find(-sum) != mp.end())
17.                     cnt += mp[-sum];
18.             }
19.         }
20.         return cnt;
21.     }
22. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top