Leetcode 447 Solution

This article provides solution to leetcode question 447 (number-of-boomerangs)

https://leetcode.com/problems/number-of-boomerangs

Solution

class Solution {
public:
    int numberOfBoomerangs(vector<pair<int, int>>& points) {
        int total = 0;

        for (int i = 0; i < points.size(); i++)
        {
            unordered_map<int, int> a;

            auto& pair1 = points[i];

            for (int j = 0; j < points.size(); j++)
            {
                auto& pair2 = points[j];

                int dis = (pair1.first - pair2.first) * (pair1.first - pair2.first) + (pair1.second - pair2.second) * (pair1.second - pair2.second);

                a[dis]++;
            }

            for (auto it = a.begin(); it != a.end(); it++)
                total += it->second * (it->second - 1);
        }

        return total;
    }
};