Max Points on a Line LeetCode solution in Python
1class Solution:2def maxPoints(self, points: List[List[int]]) -> int:3ans = 04n = len(points)56for i in range(n):7d = collections.defaultdict(int)8for j in range(n):9if i != j:10slope = float("inf")11if points[j][1] - points[i][1] != 0:12slope = (points[j][0] - points[i][0]) / (13points[j][1] - points[i][1]14)15d[slope] += 116if d:17ans = max(ans, max(d.values()) + 1)18else:19ans = max(ans, 1)2021return ans