查找表_leetcode149

Posted AceKo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查找表_leetcode149相关的知识,希望对你有一定的参考价值。

#coding=utf-8
# 解题思路: 斜率查找表 20190302 找工作期间



# Definition for a point.
# class Point(object):
# def __init__(self, a=0, b=0):
# self.x = a
# self.y = b

class Solution(object):
def maxPoints(self, points):
"""
:type points: List[Point]
:rtype: int
"""
size = len(points)
if size < 3:
return size
ans = 0
for i in range(size):
d = {‘inf‘:0}
samePoint = 1
for j in range(size):
if i == j:
continue
elif points[i].x == points[j].x and points[i].y != points[j].y:
d[‘inf‘] += 1
elif points[i].x != points[j].x:
k = 1.0 * (points[i].y - points[j].y) / (points[i].x - points[j].x)
if k in d:
d[k] += 1
else:
d[k] = 1
else:
samePoint += 1
ans = max(ans,max(d.values()) + samePoint)
return ans

以上是关于查找表_leetcode149的主要内容,如果未能解决你的问题,请参考以下文章

查找表_leetcode220

查找表_leetcode219

查找表_leetcode202

查找表_leetcode49

查找表_leetcode217

查找表_leetcode290