Skip to content

Commit 22924a0

Browse files
committed
Runtime: 251 ms (Top 43.04%) | Memory: 144 MB (Top 24.17%)
1 parent f75a28d commit 22924a0

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 251 ms (Top 43.04%) | Memory: 144 MB (Top 24.17%)
12
class Solution {
23
public int visiblePoints(List<List<Integer>> points, int angle, List<Integer> location) {
34
int overlap = 0;
@@ -6,33 +7,33 @@ public int visiblePoints(List<List<Integer>> points, int angle, List<Integer> lo
67
if (p.get(0) == location.get(0) && p.get(1) == location.get(1)) {
78
overlap++;
89
} else {
9-
list.add(angle(p.get(1) - location.get(1),
10+
list.add(angle(p.get(1) - location.get(1),
1011
p.get(0) - location.get(0)));
1112
}
1213
}
1314
Collections.sort(list);
1415
int max = 0;
1516
int n = list.size();
1617
int i2 = 0;
17-
// list.get(i1) is first angle leg
18-
// list.get(i2) is second angle leg
18+
// list.get(i1) is first angle leg
19+
// list.get(i2) is second angle leg
1920
for (int i1 = 0; i1 < n; i1++) {
20-
// let's grow i1-i2 angle as much as possible
21-
// edge case example: angle = 30, i1 = 350 degrees, i2 = 10 degrees
22-
// edge case handling: allow i2 to circle around and calculate second leg as (360 + list.get(i2 % n))
23-
// then i1 = 350, i2 = 370, delta = 20 degrees < 30 degrees
24-
while ((i2 < n && list.get(i2) - list.get(i1) <= angle) ||
21+
// let's grow i1-i2 angle as much as possible
22+
// edge case example: angle = 30, i1 = 350 degrees, i2 = 10 degrees
23+
// edge case handling: allow i2 to circle around and calculate second leg as (360 + list.get(i2 % n))
24+
// then i1 = 350, i2 = 370, delta = 20 degrees < 30 degrees
25+
while ((i2 < n && list.get(i2) - list.get(i1) <= angle) ||
2526
(i2 >= n && 360 + list.get(i2 % n) - list.get(i1) <= angle)) {
2627
i2++;
2728
}
28-
// after i2 went as far as possible away from i1 under allowed limit - check if a new maximum found
29-
max = Math.max(max, i2-i1);
29+
// after i2 went as far as possible away from i1 under allowed limit - check if a new maximum found
30+
max = Math.max(max, i2-i1);
3031
}
3132
return max + overlap;
3233
}
33-
34+
3435
private double angle(int dy, int dx) {
3536
double a = Math.toDegrees(Math.atan2(dy, dx));
3637
return (a < 0 ? a + 360 : a);
3738
}
38-
}
39+
}

0 commit comments

Comments
 (0)