Leetcode[149]直线上最多的点数

class Solution:
    def maxPoints(self, points):
        dup = collections.Counter([(p.x, p.y) for p in points])
        pt = dup.keys()
        N = len(pt)
        res = 0
        for i in range(N):
            slopm = collections.Counter()
            for j in range(i+1, N):
                dx, dy = pt[i][0] - pt[j][0], pt[i][1] - pt[j][1]
                if dx == 0: slop = None
                else: slop = float(dy)/dx
                slopm[slop] += dup[pt[j]]
            res = max(res, max(slopm.values() or [0]) + dup[pt[i]])
        return res

 

你可能感兴趣的:(python,算法,leetcode)