1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| class Solution: def visiblePoints(self, points: List[List[int]], angle: int, location: List[int]) -> int: import math angle = angle / 360 * 2 * math.pi cnt = 0 a = [] for x, y in points: if x == location[0] and y == location[1]: cnt += 1 else: xx, yy = x - location[0], y - location[1] a.append(math.atan2(yy, xx)) a.sort() n = len(a) b = [x + math.pi * 2 for x in a] a += b j = 0
ret = 0 for i in range(n): while j < len(a): if a[j] - a[i] > angle: break j += 1 ret = max(ret, j - i) return ret + cnt
|