#include<iostream>
#include<unordered_map>
using namespace std;
class Soluation {
public:
int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
unordered_map<int, int> map; // key统计A+B的数值,value保存出现的次数
int count=0;
for (int a : A) {
for (int b : B) {
map[a + b]++;
}
}
for (int c : C) {
for (int d : D) {
if (map.find(0 - c - d) != map.end()) {
count += map[0 - c - d];
}
}
}
return count;
}
};
哈希表-四数相加II-map
于 2023-09-17 17:02:47 首次发布