Python solution. Concise (3 lines) & efficient (O(n^2))


  • 0

    My solution from the contest:

    def fourSumCount(self, A, B, C, D):
        n = len(A)
        s = collections.Counter(-A[a]-B[b] for a in range(n) for b in range(n))
        return sum(s[C[c]+D[d]] for c in range(n) for d in range(n))
    

  • 0

    Come on, write that in proper Python :-)
    Would be much nicer and only take two lines.


Log in to reply
 

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