A easy solution


  • 0
    Z
    class Solution(object):
        def maxPoints(self, points):
            dic = dict()
            used = dict()
            count = dict()
            n = len(points)
            if n <= 1:
                return n
            for i in xrange(n):
                x1, y1 = points[i].x, points[i].y
                count[(x1,y1)] = count.get((x1,y1),0) + 1
                used.clear()
                for j in xrange(i):
                    x2, y2 = points[j].x, points[j].y
                    if x2 == x1 and y2 != y1 and x2 not in used:
                        used[x2] = 1
                        dic[x2] = dic.get(x2, count[(x2,y2)]) + 1
                    elif x2 != x1:
                        key = (float(y2-y1)/(x2-x1), float(x1*y2-x2*y1)/(x1-x2))
                        if key not in used:
                            used[key] = 1
                            dic[key] = dic.get(key, count[(x2,y2)]) + 1
            return max(dic.values() + count.values())
    

Log in to reply
 

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