Easy to understand Python code with O(n^2)


  • 0
    C
    This post is deleted!

  • 0
    C

    def fourSumCount(self, A, B, C, D):
    dic={}
    res=0
    for a in A:
    for b in B:
    if a+b not in dic:
    dic[a+b]=1
    else:
    dic[a+b]+=1
    for c in C:
    for d in D:
    if -c-d in dic:
    res+=dic[-c-d]
    return res


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.