[LeetCode]454. 4Sum II
454. 4Sum II
import collections
class Solution(object):
def fourSumCount(self, A, B, C, D):
"""
:type A: List[int]
:type B: List[int]
:type C: List[int]
:type D: List[int]
:rtype: int
"""
number = collections.defaultdict(int)
l = len(A)
for i in range(l):
for j in range(l):
number[A[i]+B[j]] += 1
res = 0
for i in range(l):
for j in range(l):
neg = -1 * (C[i]+D[j])
res += number[neg]
return res
![](https://i.loli.net/2018/11/17/5beff4d639cbb.jpg)
关注公众号:数据结构与算法那些事儿,每天一篇数据结构与算法