Max Points on a Line

Given _n _points on a 2D plane, find the maximum number of points that lie on the same straight line.

Example

Example 1:

Input:
 [[1,1],[2,2],[3,3]]

Output:
 3

Explanation:

^
|
|        o
|     o
|  o  
+------------->
0  1  2  3  4

Example 2:

Note

O(n^2)的方法,注意overlap

GCD算一点到其他点的斜率,i = 0: len, j = i + 1 : len

Map的key就是GCD之后的斜率,维护最大的频次,每次run外层循环进行clear和更新

Code

Last updated