Count Lattice Points Inside a Circle LeetCode solution in C++
1class Solution {2public:3bool circle(int x, int y, int c1, int c2, int r) {4if ((x - c1) * (x - c1) + (y - c2) * (y - c2) <= r * r) return true;5return false;6}78int countLatticePoints(vector<vector<int>> &circles) {9int n = circles.size(), ans = 0;10set<pair<int, int>> set;11for (auto v : circles) {12int r = v[2], x = v[0], y = v[1];13for (int i = x - r; i <= x + r; i++)14for (int j = y - r; j <= y + r; j++)15if (circle(i, j, x, y, r)) {16pair<int, int> p(i, j);17set.insert(p);18}19}20return set.size();21}22};