# 2-liner in Python, Complex solution without GCD

• Motivated by @o_sharp's solution (and I pretty much stole the title :-P).

``````from collections import Counter
from cmath import phase

class Solution(object):
def maxPoints(self, points):
P = [complex(p.x, p.y) for p in points]
return max([P.count(p) + max(Counter(phase(q - p) for q in P if q != p).values() or [0]) for p in P] or [0])
``````

Granted, it's three lines if I count the `cmath` import (LeetCode does import `collections` for us, but not `cmath`).

• Do we need to worry about the float number precision problem?
BTW just found a rational number representation: https://docs.python.org/2/library/fractions.html

• Do we need to worry about the float number precision problem?
BTW just found a rational number representation: https://docs.python.org/2/library/fractions.html

In general, we should worry about using `double` as key for hash map since it has accuracy concerns. Actually, @forsaken did some tests in this post.

To avoid this issue, my idea is to simply define an order of slope in the representation of `pair<int,int>`:
Define slope `a:=(a.x, a.y)` is less than slope `b:=(b.x, b.y)` if

• `(a.y*b.y > 0)? a.x*b.y < a.y*b.x : a.x*b.y > a.y*b.x`.

Then I have a C++ solution using `std::map` in this post.

• @zzg_zzm Ah, darn. Oh well, at least now I see it's wrong and understand why.

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