Skip to content

Commit d73914a

Browse files
committed
feat: add solutions to lc problem: No.2249
No.2249.Count Lattice Points Inside a Circle
1 parent 3227b5a commit d73914a

File tree

5 files changed

+170
-2
lines changed

5 files changed

+170
-2
lines changed

solution/2200-2299/2249.Count Lattice Points Inside a Circle/README.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,19 @@
6565
<!-- 这里可写当前语言的特殊实现逻辑 -->
6666

6767
```python
68-
68+
class Solution:
69+
def countLatticePoints(self, circles: List[List[int]]) -> int:
70+
ans = 0
71+
imx = max(x + r for x, _, r in circles)
72+
jmx = max(y + r for _, y, r in circles)
73+
for i in range(imx + 1):
74+
for j in range(jmx + 1):
75+
for x, y, r in circles:
76+
x, y = x - i, y - j
77+
if x * x + y * y <= r * r:
78+
ans += 1
79+
break
80+
return ans
6981
```
7082

7183
### **Java**
@@ -123,6 +135,53 @@ function countLatticePoints(circles: number[][]): number {
123135
};
124136
```
125137

138+
### **C++**
139+
140+
```cpp
141+
class Solution {
142+
public:
143+
int countLatticePoints(vector<vector<int>>& circles) {
144+
int ans = 0;
145+
for (int i = 0; i <= 200; ++i)
146+
{
147+
for (int j = 0; j <= 200; ++j)
148+
{
149+
for (auto& c : circles)
150+
{
151+
int x = c[0] - i, y = c[1] - j, r = c[2];
152+
if (x * x + y * y <= r * r)
153+
{
154+
++ans;
155+
break;
156+
}
157+
}
158+
}
159+
}
160+
return ans;
161+
}
162+
};
163+
```
164+
165+
### **Go**
166+
167+
```go
168+
func countLatticePoints(circles [][]int) int {
169+
ans := 0
170+
for i := 0; i <= 200; i++ {
171+
for j := 0; j <= 200; j++ {
172+
for _, c := range circles {
173+
x, y, r := c[0]-i, c[1]-j, c[2]
174+
if x*x+y*y <= r*r {
175+
ans++
176+
break
177+
}
178+
}
179+
}
180+
}
181+
return ans
182+
}
183+
```
184+
126185
### **...**
127186

128187
```

solution/2200-2299/2249.Count Lattice Points Inside a Circle/README_EN.md

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,19 @@ Some of them are (0, 2), (2, 0), (2, 4), (3, 2), and (4, 4).
5353
### **Python3**
5454

5555
```python
56-
56+
class Solution:
57+
def countLatticePoints(self, circles: List[List[int]]) -> int:
58+
ans = 0
59+
imx = max(x + r for x, _, r in circles)
60+
jmx = max(y + r for _, y, r in circles)
61+
for i in range(imx + 1):
62+
for j in range(jmx + 1):
63+
for x, y, r in circles:
64+
x, y = x - i, y - j
65+
if x * x + y * y <= r * r:
66+
ans += 1
67+
break
68+
return ans
5769
```
5870

5971
### **Java**
@@ -109,6 +121,53 @@ function countLatticePoints(circles: number[][]): number {
109121
};
110122
```
111123

124+
### **C++**
125+
126+
```cpp
127+
class Solution {
128+
public:
129+
int countLatticePoints(vector<vector<int>>& circles) {
130+
int ans = 0;
131+
for (int i = 0; i <= 200; ++i)
132+
{
133+
for (int j = 0; j <= 200; ++j)
134+
{
135+
for (auto& c : circles)
136+
{
137+
int x = c[0] - i, y = c[1] - j, r = c[2];
138+
if (x * x + y * y <= r * r)
139+
{
140+
++ans;
141+
break;
142+
}
143+
}
144+
}
145+
}
146+
return ans;
147+
}
148+
};
149+
```
150+
151+
### **Go**
152+
153+
```go
154+
func countLatticePoints(circles [][]int) int {
155+
ans := 0
156+
for i := 0; i <= 200; i++ {
157+
for j := 0; j <= 200; j++ {
158+
for _, c := range circles {
159+
x, y, r := c[0]-i, c[1]-j, c[2]
160+
if x*x+y*y <= r*r {
161+
ans++
162+
break
163+
}
164+
}
165+
}
166+
}
167+
return ans
168+
}
169+
```
170+
112171
### **...**
113172

114173
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int countLatticePoints(vector<vector<int>>& circles) {
4+
int ans = 0;
5+
for (int i = 0; i <= 200; ++i)
6+
{
7+
for (int j = 0; j <= 200; ++j)
8+
{
9+
for (auto& c : circles)
10+
{
11+
int x = c[0] - i, y = c[1] - j, r = c[2];
12+
if (x * x + y * y <= r * r)
13+
{
14+
++ans;
15+
break;
16+
}
17+
}
18+
}
19+
}
20+
return ans;
21+
}
22+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
func countLatticePoints(circles [][]int) int {
2+
ans := 0
3+
for i := 0; i <= 200; i++ {
4+
for j := 0; j <= 200; j++ {
5+
for _, c := range circles {
6+
x, y, r := c[0]-i, c[1]-j, c[2]
7+
if x*x+y*y <= r*r {
8+
ans++
9+
break
10+
}
11+
}
12+
}
13+
}
14+
return ans
15+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Solution:
2+
def countLatticePoints(self, circles: List[List[int]]) -> int:
3+
ans = 0
4+
imx = max(x + r for x, _, r in circles)
5+
jmx = max(y + r for _, y, r in circles)
6+
for i in range(imx + 1):
7+
for j in range(jmx + 1):
8+
for x, y, r in circles:
9+
x, y = x - i, y - j
10+
if x * x + y * y <= r * r:
11+
ans += 1
12+
break
13+
return ans

0 commit comments

Comments
 (0)