forked from Garvit244/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path454.py
More file actions
25 lines (22 loc) · 631 Bytes
/
454.py
File metadata and controls
25 lines (22 loc) · 631 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
"""
hashTable ={}
for a in A:
for b in B:
if a+b in hashTable:
hashTable[a+b] += 1
else:
hashTable[a+b] = 1
result = 0
for c in C:
for d in D:
if -(c+d) in hashTable:
result += hashTable[-(c+d)]
return result