#2249

Count Lattice Points Inside a Circle

specialist · 825 · lc medium +31 · verified · 56.5% accepted · 253 likes · top 51%

Description

You are given a 2D integer array circles where circles[i] = [xi, yi, ri] describes a circle centered at (xi, yi) with radius ri drawn on a coordinate grid.

Return the total number of integer-coordinate (lattice) points that lie inside at least one circle.

Note:

- A lattice point has integer coordinates.

- A point on the boundary of a circle is considered inside it.

Example 1:

Input: circles = [[2,2,1]]
Output: 5
Explanation:
The figure above shows the given circle.
The lattice points present inside the circle are (1, 2), (2, 1), (2, 2), (2, 3), and (3, 2) and are shown in green.
Other points such as (1, 1) and (1, 3), which are shown in red, are not considered inside the circle.
Hence, the number of lattice points present inside at least one circle is 5.

Example 2:

Input: circles = [[2,2,2],[3,4,1]]
Output: 16
Explanation:
The figure above shows the given circles.
There are exactly 16 lattice points which are present inside at least one circle.
Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).

Code

1
2
3