mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2026-02-02 18:39:09 +08:00
Merge pull request #2907 from zenwangzy/master
Update 0454.四数相加II,力扣函数参数更新,故更新对应题解代码
This commit is contained in:
@@ -60,18 +60,18 @@ C++代码:
|
||||
```CPP
|
||||
class Solution {
|
||||
public:
|
||||
int fourSumCount(vector<int>& A, vector<int>& B, vector<int>& C, vector<int>& D) {
|
||||
int fourSumCount(vector<int>& nums1, vector<int>& nums2, vector<int>& nums3, vector<int>& nums4) {
|
||||
unordered_map<int, int> umap; //key:a+b的数值,value:a+b数值出现的次数
|
||||
// 遍历大A和大B数组,统计两个数组元素之和,和出现的次数,放到map中
|
||||
for (int a : A) {
|
||||
for (int b : B) {
|
||||
for (int a : nums1) {
|
||||
for (int b : nums2) {
|
||||
umap[a + b]++;
|
||||
}
|
||||
}
|
||||
int count = 0; // 统计a+b+c+d = 0 出现的次数
|
||||
// 再遍历大C和大D数组,找到如果 0-(c+d) 在map中出现过的话,就把map中key对应的value也就是出现次数统计出来。
|
||||
for (int c : C) {
|
||||
for (int d : D) {
|
||||
for (int c : nums3) {
|
||||
for (int d : nums4) {
|
||||
if (umap.find(0 - (c + d)) != umap.end()) {
|
||||
count += umap[0 - (c + d)];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user