当前位置:网站首页>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).
边栏推荐
- 171. excel table column No
- The combination of applet container technology and IOT
- “目标检测“+“视觉理解“实现对输入图像的理解
- 392. judgment subsequence
- 【EI会议】2022年第三届纳米材料与纳米技术国际会议(NanoMT 2022)
- Web components series (VIII) -- custom component style settings
- [JPCs publication] the Third International Conference on control theory and application in 2022 (icocta 2022)
- Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
- Unexpected token o in JSON at position 1, JSON parsing problem
- [TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation
猜你喜欢

How to display scrollbars on the right side of the background system and how to solve the problem of double scrollbars

JMeter login failure, extracting login token, and obtaining token problem solving

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

NFT:使用 EIP-2981 开启 NFT 版税之旅

【TA-霜狼_may-《百人计划》】2.2 模型与材质空间

Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
![[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis](/img/94/99090ea91082a385968e071ef3766c.png)
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis

Huawei simulator ENSP - hcip - Hybrid Experiment 2
![[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation](/img/49/173b1f1f379faa28c503165a300ce0.png)
[TA frost wolf \u may- hundred talents plan] 1.2.2 matrix calculation

使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
随机推荐
Are you still wasting brain cells for self-study? This interview note is definitely the ceiling of station C
盘点华为云GaussDB(for Redis)六大秒级能力
MFC窗口滚动条用法
4. [WebGIS practice] software operation chapter - data import and processing
Jeecgboot output log, how to use @slf4j
5. [WebGIS practice] software operation - service release and permission management
[party benefits] jsonobject to string, leave blank
206.反转链表
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
Usage of AfxMessageBox and MessageBox
214. minimum palindrome string
10. 正则表达式匹配
Network metering - application layer
25.K个一组翻转链表
Idea plug-in backup table
Future of NTF and trends in 2022
Volley parsing data shows networking failure
Use of comment keyword in database
Web components series (VIII) -- custom component style settings
基于Unet的环路滤波