Leetcode—1828. 统计一个圆中点的数目【中等】

2024每日刷题(一零五)

Leetcode—1828. 统计一个圆中点的数目

Leetcode—1828. 统计一个圆中点的数目【中等】_第1张图片

实现代码

class Solution {
public:
    vector<int> countPoints(vector<vector<int>>& points, vector<vector<int>>& queries) {
        vector<int> ans;
        for(auto& q: queries) {
            int x0 = q[0];
            int y0 = q[1];
            int r =  q[2];
            int cnt = 0;
            for(auto& it: points) {
                int dx = it[0] - x0;
                int dy = it[1] - y0;
                cnt += dx * dx + dy * dy <= r * r;
            }
            ans.push_back(cnt);
        }
        return ans;
    }
};

运行结果

Leetcode—1828. 统计一个圆中点的数目【中等】_第2张图片
之后我会持续更新,如果喜欢我的文章,请记得一键三连哦,点赞关注收藏,你的每一个赞每一份关注每一次收藏都将是我前进路上的无限动力 !!!↖(▔▽▔)↗感谢支持!

你可能感兴趣的:(LeetCode刷题,leetcode,算法,职场和发展,c++,经验分享,枚举,数组)