2249. Count Lattice Points Inside a Circle

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2249

class Solution:
    def countLatticePoints(self, circles: List[List[int]]) -> int:
        res = 0
        mx = max(x + r for x, _, r in circles)
        my = max(y + r for _, y, r in circles)
        for i in range(mx + 1):
            for j in range(my + 1):
                for x, y, r in circles:
                    dx, dy = i - x, j - y
                    if dx * dx + dy * dy <= r * r:
                        res += 1
                        break
        return res