@@ -48,21 +48,90 @@ queries[0] is green, queries[1] is red, queries[2] is blue, and queries[3] is pu
48
48
<p >  ; </p >
49
49
<p ><strong >Follow up:</strong > Could you find the answer for each query in better complexity than <code >O(n)</code >?</p >
50
50
51
-
52
51
## Solutions
53
52
54
53
<!-- tabs:start -->
55
54
56
55
### ** Python3**
57
56
58
57
``` python
59
-
58
+ class Solution :
59
+ def countPoints (self , points : List[List[int ]], queries : List[List[int ]]) -> List[int ]:
60
+ ans = []
61
+ for x0, y0, r in queries:
62
+ count = 0
63
+ for x, y in points:
64
+ dx, dy = x - x0, y - y0
65
+ if dx * dx + dy * dy <= r * r:
66
+ count += 1
67
+ ans.append(count)
68
+ return ans
60
69
```
61
70
62
71
### ** Java**
63
72
64
73
``` java
74
+ class Solution {
75
+ public int [] countPoints (int [][] points , int [][] queries ) {
76
+ int [] ans = new int [queries. length];
77
+ int i = 0 ;
78
+ for (int [] query : queries) {
79
+ int x0 = query[0 ], y0 = query[1 ], r = query[2 ];
80
+ for (int [] point : points) {
81
+ int x = point[0 ], y = point[1 ];
82
+ int dx = x - x0, dy = y - y0;
83
+ if (dx * dx + dy * dy <= r * r) {
84
+ ++ ans[i];
85
+ }
86
+ }
87
+ ++ i;
88
+ }
89
+ return ans;
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### ** C++**
95
+
96
+ ``` cpp
97
+ class Solution {
98
+ public:
99
+ vector<int > countPoints(vector<vector<int >>& points, vector<vector<int >>& queries) {
100
+ vector<int > ans;
101
+ for (auto& query : queries) {
102
+ int x0 = query[ 0] , y0 = query[ 1] , r = query[ 2] ;
103
+ int count = 0;
104
+ for (auto& point : points) {
105
+ int x = point[ 0] , y = point[ 1] ;
106
+ int dx = x - x0, dy = y - y0;
107
+ if (dx * dx + dy * dy <= r * r) {
108
+ ++count;
109
+ }
110
+ }
111
+ ans.push_back(count);
112
+ }
113
+ return ans;
114
+ }
115
+ };
116
+ ```
65
117
118
+ ### **Go**
119
+
120
+ ```go
121
+ func countPoints(points [][]int, queries [][]int) []int {
122
+ ans := make([]int, len(queries))
123
+ for i, query := range queries {
124
+ x0, y0, r := query[0], query[1], query[2]
125
+ for _, point := range points {
126
+ x, y := point[0], point[1]
127
+ dx, dy := x-x0, y-y0
128
+ if dx*dx+dy*dy <= r*r {
129
+ ans[i]++
130
+ }
131
+ }
132
+ }
133
+ return ans
134
+ }
66
135
```
67
136
68
137
### ** ...**
0 commit comments