Skip to content

Commit

Permalink
update 0454.四数相加II:完善注释
Browse files Browse the repository at this point in the history
  • Loading branch information
juguagua authored Nov 24, 2022
1 parent 4796c81 commit b0f84a4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions problems/0454.四数相加II.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,15 @@ Go:

```go
func fourSumCount(nums1 []int, nums2 []int, nums3 []int, nums4 []int) int {
m := make(map[int]int)
m := make(map[int]int) //key:a+b的数值,value:a+b数值出现的次数
count := 0
for _, v1 := range nums1 {
// 遍历nums1和nums2数组,统计两个数组元素之和,和出现的次数,放到map中
for _, v1 := range nums1 {
for _, v2 := range nums2 {
m[v1+v2]++
}
}
// 遍历nums3和nums4数组,找到如果 0-(c+d) 在map中出现过的话,就把map中key对应的value也就是出现次数统计出来
for _, v3 := range nums3 {
for _, v4 := range nums4 {
count += m[-v3-v4]
Expand All @@ -197,14 +199,14 @@ javaScript:
var fourSumCount = function(nums1, nums2, nums3, nums4) {
const twoSumMap = new Map();
let count = 0;

// 统计nums1和nums2数组元素之和,和出现的次数,放到map中
for(const n1 of nums1) {
for(const n2 of nums2) {
const sum = n1 + n2;
twoSumMap.set(sum, (twoSumMap.get(sum) || 0) + 1)
}
}

// 找到如果 0-(c+d) 在map中出现过的话,就把map中key对应的value也就是出现次数统计出来
for(const n3 of nums3) {
for(const n4 of nums4) {
const sum = n3 + n4;
Expand Down

0 comments on commit b0f84a4

Please sign in to comment.