Number of Boomerangs
Input:
[[0,0],[1,0],[2,0]]
Output:
2
Explanation:
The two boomerangs are
[[1,0],[0,0],[2,0]]
and
[[1,0],[2,0],[0,0]]Last updated
Input:
[[0,0],[1,0],[2,0]]
Output:
2
Explanation:
The two boomerangs are
[[1,0],[0,0],[2,0]]
and
[[1,0],[2,0],[0,0]]Last updated
class Solution(object):
def numberOfBoomerangs(self, points):
"""
:type points: List[List[int]]
:rtype: int
"""
ans = 0
for x1, y1 in points:
dmap = collections.defaultdict(int)
for x2, y2 in points:
dmap[(x1 - x2) ** 2 + (y1 - y2) ** 2] += 1
for d in dmap:
ans += dmap[d] * (dmap[d] - 1)
return ans