Max Points on a Line
ID:149
Last updated
ID:149
Last updated
Given an array of points
where points[i] = [xi, yi]
represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.
Since the deterministic factor to decide whether two points are on a line, the slope of two is important. Therefore, we need to record the number of points with the same slope
But a key point is, like in the above example, (1,1),(2,3) and (4,1),(5,3) has the same slope, but they cannot be counted together since they are not on the same line.
Therefore, we need to construct a seperate table for each base point. For example, for base point(1,1), only (2,3) can be counted since they are of slope 2, but (4,1) and (5,3) will not be counted.
There's a special case, where two points are on a vertical line. In this case, the slope of deltaY/deltaX is undefined, since deltaX = 0. Therefore, we count this special case with another if condition.