2249. Count Lattice Points Inside a Circle¶
Approach 1: Math¶
- Time: $O(200^2n) = O(n)$
- Space: $O(1)$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
1 2 3 4 5 |
|
Approach 2: Set¶
- Time: $O(n\log n \cdot r^2)$ (C++), $O(nr^2) = O(n)$ (Java/Python)
- Space: $O(nr^2) = O(n)$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|