leetcode 447. Number of Boomerangs

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;
    }
};

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章