Queries on Number of Points Inside a Circle
给一个2d数组是points, 然后给一个数组里面是queries, query里面有一个圆的圆点坐标x,y和半径r, 求这个圆里面有多少个点.
这个题就是利用每个query的圆点位置和points的位置求解
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
class Solution { public int[] countPoints(int[][] points, int[][] queries) { int[] res = new int[queries.length]; for(int i = 0; i < queries.length; i++){ int count = 0; for(int j = 0; j < points.length; j++) { if(dis(queries[i][0], queries[i][1], points[j][0], points[j][1]) <= (queries[i][2] * queries[i][2])){ count++; } } res[i] = count; } return res; } private double dis(int x1, int y1, int x2, int y2) { return Math.pow(x2 - x1, 2) + Math.pow(y2 -y1, 2); } } |