Number of Boomerangs

Problem Id: 447 Difficulty: Medium


Intuition

Solution


class Solution:
    def numberOfBoomerangs(self, points: List[List[int]]) -> int:
        ans = 0
        for i in range(len(points)):
            distances = {}
            for j in range(len(points)):
                if i == j:
                    continue
                dis = (points[i][0] - points[j][0]) ** 2 + (points[i][1] - points[j][1]) ** 2
                if dis not in distances:
                    distances[dis] = 0
                distances[dis] += 1
            for k in distances.keys():
                ans += distances[k] * (distances[k] - 1)
        return ans