Maximum Number of Visible Points LeetCode solution in Python

1
# Runtime: 5206 ms (Top 8.11%) | Memory: 46.3 MB (Top 98.26%)
2
class Solution:
3
def visiblePoints(
4
self, points: List[List[int]], angle: int, location: List[int]
5
) -> int:
6

7
arr, extra = [], 0
8
xx, yy = location
9

10
for x, y in points:
11
if x == xx and y == yy:
12
extra += 1
13
continue
14
arr.append(math.atan2(y - yy, x - xx))
15

16
arr.sort()
17
arr = arr + [x + 2.0 * math.pi for x in arr]
18
angle = math.pi * angle / 180
19

20
l = ans = 0
21
for r in range(len(arr)):
22
while arr[r] - arr[l] > angle:
23
l += 1
24
ans = max(ans, r - l + 1)
25

26
return ans + extra

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0