当前位置:网站首页>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).
边栏推荐
- NFT:使用 EIP-2981 开启 NFT 版税之旅
- 165. compare version numbers
- 30. 串联所有单词的子串
- 431. 将 N 叉树编码为二叉树 DFS
- Complete knapsack problem
- [ta- frost wolf \u may- hundred people plan] 2.2 model and material space
- Use selenium automated test tool to climb the enrollment score line and ranking of colleges and universities related to the college entrance examination
- Pytorch training deep learning network settings CUDA specified GPU visible
- [shortcut key]
- Jenkins自动清理构建历史
猜你喜欢

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

Go learning --- unit test subtest

不同性能测试工具的并发模式

Review column - message queue
![[TA frost wolf \u may- hundred people plan] 1.3 secret of texture](/img/dc/ce2819258632cdcf2e130a4c05600e.png)
[TA frost wolf \u may- hundred people plan] 1.3 secret of texture

Sort linked list (merge sort)

Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)

SEM of C language_ Tvariable type

盘点华为云GaussDB(for Redis)六大秒级能力

Deep learning | rnn/lstm of naturallanguageprocessing
随机推荐
205. isomorphic string
Deep learning | rnn/lstm of naturallanguageprocessing
【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
The difference between MFC for static libraries and MFC for shared libraries
NFT:使用 EIP-2981 开启 NFT 版税之旅
10、Scanner. Next() cannot read spaces /indexof -1
214. minimum palindrome string
Complete knapsack problem
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
10. regular expression matching
【伸手党福利】开发人员重装系统顺序
392. judgment subsequence
Web components series (VIII) -- custom component style settings
You cannot right-click F12 to view the source code solution on the web page
【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
Use of JMeter counters
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
[ta- frost wolf \u may- hundred people plan] 2.2 model and material space
165. 比较版本号