Count Lattice Points Inside a Circle LeetCode solution in Java

1
class Solution {
2
public int countLatticePoints(int[][] circles) {
3
Set<String> answer = new HashSet<String>();
4

5
for (int[] c : circles) {
6
int x = c[0], y = c[1], r = c[2];
7

8
// traversing over all the points that lie inside the smallest square capable of containing
9
// the whole circle
10
for (int xx = x - r; xx <= x + r; xx++)
11
for (int yy = y - r; yy <= y + r; yy++)
12
if ((r * r) >= ((x - xx) * (x - xx)) + ((y - yy) * (y - yy))) answer.add(xx + ":" + yy);
13
}
14

15
return answer.size();
16
}
17
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0