Simple math: a line can be uniquely represented by `y=ax+b`

or `x=c`

(vertical-line case).

We can iterate through all pairs of points and find the line that the 2 points are forming. The hash key tuple for the line is either `(a, b)`

or `(float('inf'), c)`

.

By doing that, all points are grouped by unique lines.

Then we count the number of unique points for each line and return the maximum.

```
class Solution(object):
def maxPoints(self, points):
d = collections.defaultdict(set)
for i in range(1, len(points)):
for j in range(i):
p1, p2 = points[i], points[j]
d[(float('inf'), p1.x) if p1.x==p2.x else ((p1.y-p2.y)/float(p1.x-p2.x), (p1.x*p2.y-p2.x*p1.y)/float(p1.x-p2.x))] |= set([p1, p2])
return max(len(s) for s in d.values()) if len(points)>1 else len(points)
```

Or the longer but easier-to-read version:

```
class Solution(object):
def maxPoints(self, points):
d = collections.defaultdict(list)
for i in range(1, len(points)):
for j in range(i):
p1, p2 = points[i], points[j]
if p1.x == p2.x:
t = (float('inf'), p1.x)
else:
t = ((p1.y-p2.y)/float(p1.x-p2.x), (p1.x*p2.y-p2.x*p1.y)/float(p1.x-p2.x))
d[t] += [p1, p2]
return max(len(set(l)) for l in d.values()) if len(points)>1 else len(points)
```