149. Max Points on a Line

xiaoxiao2021-02-28  71

import numpy as np class Solution(object):     def maxPoints(self, points):         """         :type points: List[Point]         :rtype: int         """         l = len(points)         m = 0         for i in range(l):             dic = {'i': 1}             same = 0             for j in range(i+1, l):                 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 dic: dic[slope] = 1                 dic[slope] += 1             m = max(m, max(dic.values()) + same)         return m
转载请注明原文地址: https://www.6miu.com/read-52852.html

最新回复(0)