149. Max Points on a Line

def maxPoints(self, points):
        """
        :type points: List[Point]
        :rtype: int
        """
        import numpy as np
        size = len(points)
        res = 0
        for i in xrange(size):
            d = {'i': 1}
            same = 0
            for j in xrange(i + 1, size):
                tx, ty = points[j].x, points[j].y
                if tx == points[i].x and ty == points[i].y:
                    same += 1
                    continue
                if points[i].x == tx: slope = 'i'
                else:
                    slope = ((points[i].y - ty) * np.longdouble(1)) / (points[i].x - tx)
                if slope not in d: d[slope] = 1
                d[slope] += 1
            res = max(res, max(d.values()) + same)
        return res

results matching ""

    No results matching ""