Skip to content

Commit 0197241

Browse files
authored
Update LineSweep.java
If i starts with 1, then the first point will never be added to the candidates set so it will not be considered as a candidate to other points. Check this example. 4 -1 0 0 100 0 200 1 0 The closest distance between the first and the fourth point is 2 but the current solution will result in d = 100.
1 parent 78c2270 commit 0197241

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

geometry/LineSweep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static void main(String[] args) throws NumberFormatException, IOException
2121
Arrays.sort(points, new X());
2222

2323
double d = 1e9;
24-
for(int i = 1, left = 0; i < points.length; i++)
24+
for(int i = 0, left = 0; i < points.length; i++)
2525
{
2626
int px = points[i].x, py = points[i].y;
2727
while(left < i && px - points[left].x > d + EPS) cands.remove(points[left++]);

0 commit comments

Comments
 (0)