// 454: 4sum-II; 求个数
function fourSum2(numsA, numsB, numsC, numsD) {
let map = {}
for (let i = 0, len = numsC.length; i < len; i++) {
let item = numsC[i]
for (let j = 0, len = numsD.length; j < len; j++) {
let c = list[j]
if (typeof map[item + c] === 'undefined') {
map[item + c] = 0
} else {
map[item + c]++
}
}
}
let res = 0
for (let i = 0, len = numsA.length; i < len; i++) {
for (let j = 0, len = numsB.length; j < len; j++) {
let m = map[0 - numsA[i] - numsB[j]]
if (typeof m !== 'undefined') {
res += m
}
}
}
return res
}
网友评论