5-line Simple Python Solution with Hash O(n^2)


  • 0
    G

    Happy if you can give any advise.

    class Solution(object):
        def numberOfBoomerangs(self, points):
            rst = 0
            for idx,i in enumerate(points):
                dists = [(i[0]-j[0])**2+(i[1]-j[1])**2 for j in points]
                rst += sum([val*(val-1) for val in collections.Counter(dists).values() if val>=2])
            return rst
    

Log in to reply
 

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