leetcode 447. Number of Boomerangs

来源:互联网 发布:淘宝联盟好用吗 编辑:程序博客网 时间:2024/05/16 14:13
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;    }};

0 0
原创粉丝点击