# JAVA----------Easy Version To UnderStand!!!!!!!!

• `````` public int maxPoints(Point[] points) {
if (points == null || points.length == 0)
return 0;
if (points.length <= 2)
return points.length;
int max = 0;
for (int i = 0; i < points.length; i++) {
HashMap<Double, Integer> map = new HashMap<>();
int samePoint = 0, sameX = 0;
for (int j = 0; j < points.length; j++) {
if (i == j)
continue;
if (points[j].x == points[i].x && points[j].y == points[i].y){
samePoint++;
sameX++;
continue;
}
else if (points[j].x == points[i].x) {
sameX++;
continue;
}
double k = (double) (points[j].y - points[i].y) / (double) (points[j].x - points[i].x);
if (map.get(k) == null)
map.put(k, 2);
else
map.put(k, map.get(k) + 1);
}

for (Double k : map.keySet()) {
max = Integer.max(max, map.get(k) + samePoint);
}
max = Integer.max(max, sameX+1);
}
return max;
}``````

• The solution looks not complete?

• It is complete.It has been AC

• Er, the code you copied is not complete.

• This post is deleted!

• Two parallel line have same slope but that case is not handled here.Why?

Suppose, two points lie on first line and other two points lie on other line, so slope from 1st and 2nd will be same as from 3rd and 4th, but they are not on same line.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.