Leetcode 447 Solution
This article provides solution to leetcode question 447 (number-of-boomerangs)
Access this page by simply typing in "lcs 447" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
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;
}
};