Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fractions import Fraction as fr
- f=math.factorial
- class Solution:
- def maxPoints(self, points: List[List[int]]) -> int:
- def ncr(n,r):
- return f(n)//f(r)//f(n-r)
- n=len(points)
- slope = lambda x1,y1,x2,y2:(y2-y1)/(x2-x1)
- d=defaultdict(set)
- ans=0
- if n==1:return 1
- for i in range(n):
- for j in range(i+1,n):
- x1,y1=points[i]
- x2,y2=points[j]
- if x1==x2:
- d[(inf,x1)].update({i,j})
- else:
- sp=fr(y2-y1,x2-x1)
- incept=y1-sp*x1
- d[(sp,incept)].update({i,j})
- ans=0
- for i in d.values():
- t=len(i)
- if t>=3:
- ans+=ncr(t,3)
- return ans
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement