class Solution {
public:
int numberOfBoomerangs(vector<pair<int, int>>& points) {
unordered_map<int,int> haha;
int ans = 0;
for(int i = 0;i < points.size(); i++){
haha.clear();
for(int j = 0; j < points.size(); j++){
int x = points[i].first - points[j].first;
int y = points[i].second - points[j].second;
int d = x*x + y*y;
ans += haha[d];
haha[d]+=2;
}
}
return ans;
}
};
leetcode 447. Number of Boomerangs
最新推荐文章于 2024-11-01 15:19:21 发布