447. 回旋镖的数量

Posted 这是一个很随便的名字

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了447. 回旋镖的数量相关的知识,希望对你有一定的参考价值。

给定平面上 n 对 互不相同 的点 points ,其中 points[i] = [xi, yi] 。回旋镖 是由点 (i, j, k) 表示的元组 ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序)。

返回平面上所有回旋镖的数量。
示例 1:

输入:points = [[0,0],[1,0],[2,0]]
输出:2
解释:两个回旋镖为 [[1,0],[0,0],[2,0]] 和 [[1,0],[2,0],[0,0]]
示例 2:

输入:points = [[1,1],[2,2],[3,3]]
输出:2
示例 3:

输入:points = [[1,1]]
输出:0

提示:

n == points.length
1 <= n <= 500
points[i].length == 2
-104 <= xi, yi <= 104
所有点都 互不相同

class Solution {
public:
    int numberOfBoomerangs(vector<vector<int>>& points) {
        int dis = 0;
        int ret = 0;
        for(int i = 0;i<points.size();i++)
        {
            unordered_map<int,int> mp;
            for(int j = 0;j<points.size();j++)
            {
                if(i==j) continue;
                dis = (points[i][0]-points[j][0])*(points[i][0]-points[j][0])+(points[i][1]-points[j][1])*(points[i][1]-points[j][1]);
                mp[dis]++;
            }
            for(auto& [_,v]:mp)
            {
                ret+=v*(v-1);
            }
        }
        return ret;
    }
};

以上是关于447. 回旋镖的数量的主要内容,如果未能解决你的问题,请参考以下文章

447. 回旋镖的数量

447. 回旋镖的数量

447 Number of Boomerangs 回旋镖的数量

leetcode中等447回旋镖的数量

Leetcode刷题100天—447. 回旋镖的数量( 哈希表)—day37

Leetcode刷题100天—447. 回旋镖的数量( 哈希表)—day37