Skip to content

Commit de888d2

Browse files
committed
Add some comments for MaxPointsOnALine
1 parent 82334b9 commit de888d2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

MaxPointsOnALine.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public int hashCode() {
5151
+ Double.toString(mIntercept).hashCode();
5252
}
5353
}
54+
5455
public int maxPoints(Point[] points) {
5556
Map<Line, Integer> map = new HashMap<Line, Integer>();
5657
int ret = 0;
@@ -61,6 +62,7 @@ public int maxPoints(Point[] points) {
6162
Line line = null;
6263
if (points[j].x == points[i].x) {
6364
if (points[j].y == points[i].y) {
65+
// Record how many times the same "start" point occurs.
6466
dup++;
6567
continue;
6668
}
@@ -78,15 +80,15 @@ public int maxPoints(Point[] points) {
7880
map.put(line, 2);
7981
}
8082
}
83+
// Now check all lines which contains the current "start" point (point[i]).
8184
for (Integer count : map.values()) {
8285
ret = Math.max(ret, count.intValue() + dup);
8386
}
8487
map.clear();
8588
}
89+
// If we got ret as 0, all points in input array should be exactly the
90+
// same point so that we cannot construct a line. So just need to return
91+
// the length of the input array since all these points are in the same line.
8692
return ret > 0 ? ret : points.length;
8793
}
88-
89-
public static void main(String[] args) {
90-
System.out.println(new MaxPointsOnALine().maxPoints(new Point[] {new Point(0,0),new Point(0,0)}));
91-
}
9294
}

0 commit comments

Comments
 (0)