当前位置:网站首页>LeetCode 1828. Count the number of points in a circle
LeetCode 1828. Count the number of points in a circle
2022-07-01 03:52:00 【Daylight629】
1828. Count the number of points in a circle
Give you an array points , among points[i] = [xi, yi] , It means the first one i The coordinates of a point on a two-dimensional plane . Multiple points may have identical Coordinates of .
I'll give you an array at the same time queries , among queries[j] = [xj, yj, rj] , The center of a circle (xj, yj) And the radius is rj The circle of .
For every query queries[j] , The calculation is in j Circle Inside Number of points . If a point is on the edge of a circle On the border , We also think it's round Inside .
Please return an array answer , among answer[j] It's No j The answer to a query .
Example 1:

Input :points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]
Output :[3,2,2]
explain : All the points and circles are shown in the figure above .
queries[0] It's a green circle ,queries[1] It's a red circle ,queries[2] It's a blue circle .
Example 2:

Input :points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]
Output :[2,3,2,4]
explain : All the points and circles are shown in the figure above .
queries[0] It's a green circle ,queries[1] It's a red circle ,queries[2] It's a blue circle ,queries[3] It's a purple circle .
Tips :
1 <= points.length <= 500points[i].length == 20 <= xi, yi <= 5001 <= queries.length <= 500queries[j].length == 30 <= xj, yj <= 5001 <= rj <= 500- All coordinates are integers .
Two 、 Method 1
simulation
class Solution {
public int[] countPoints(int[][] points, int[][] queries) {
int[] answer = new int[queries.length];
for(int i=0;i<queries.length;i++){
int[] cur = queries[i];
int x = cur[0];
int y = cur[1];
int r = cur[2];
int sum=0;
for(int[] p:points){
int a = p[0] - x;
int b = p[1]- y;
if(a*a+b*b<=r*r) sum++;
}
answer[i] = sum;
}
return answer;
}
}
Complexity analysis
Time complexity :O(n).
Spatial complexity :O(1).
边栏推荐
- Pytorch training deep learning network settings CUDA specified GPU visible
- 浏览器顶部loading(来自知乎)
- [TA frost wolf \u may- hundred people plan] 1.3 secret of texture
- 这可能是你进腾讯最后的机会了..
- “目标检测“+“视觉理解“实现对输入图像的理解
- [TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
- All in one 1086: Jiaogu conjecture
- The programmer's girlfriend gave me a fatigue driving test
- bootsrap中的栅格系统
- What does ft mean in the data book table
猜你喜欢

“目标检测“+“视觉理解“实现对输入图像的理解

[TA frost wolf \u may - "hundred people plan"] 2.1 color space

程序员女友给我做了一个疲劳驾驶检测

复习专栏之---消息队列

Unexpected token o in JSON at position 1, JSON parsing problem

TEC: Knowledge Graph Embedding with Triple Context

Idea plug-in backup table

【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型

Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products

431. 将 N 叉树编码为二叉树 DFS
随机推荐
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
The combination of applet container technology and IOT
389. find a difference
“目标检测“+“视觉理解“实现对输入图像的理解
【历史上的今天】6 月 30 日:冯·诺依曼发表第一份草案;九十年代末的半导体大战;CBS 收购 CNET
【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
[EI conference] 2022 international joint civil and Offshore Engineering Conference (jccme 2022)
8. string conversion integer (ATOI)
[shortcut key]
6. zigzag transformation
Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
208. implement trie (prefix tree)
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis
10. 正则表达式匹配
Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
[ta - Frost Wolf May - 100 people plan] 2.3 Introduction aux fonctions communes
72. 编辑距离
[party benefits] jsonobject to string, leave blank
431. 将 N 叉树编码为二叉树 DFS
谷粒学院微信扫码登录过程记录以及bug解决