mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
添加第454题.四数相加IIJavaScript版本
This commit is contained in:
@ -155,6 +155,38 @@ class Solution(object):
|
|||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
javaScript:
|
||||||
|
|
||||||
|
```js
|
||||||
|
/**
|
||||||
|
* @param {number[]} nums1
|
||||||
|
* @param {number[]} nums2
|
||||||
|
* @param {number[]} nums3
|
||||||
|
* @param {number[]} nums4
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
var fourSumCount = function(nums1, nums2, nums3, nums4) {
|
||||||
|
const twoSumMap = new Map();
|
||||||
|
let count = 0;
|
||||||
|
|
||||||
|
for(const n1 of nums1) {
|
||||||
|
for(const n2 of nums2) {
|
||||||
|
const sum = n1 + n2;
|
||||||
|
twoSumMap.set(sum, (twoSumMap.get(sum) || 0) + 1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(const n3 of nums3) {
|
||||||
|
for(const n4 of nums4) {
|
||||||
|
const sum = n3 + n4;
|
||||||
|
count += (twoSumMap.get(0 - sum) || 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user