Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane, return the maximum number of points that lie on the same straight line.
classSolution: defmaxPoints(self, points: List[List[int]]) -> int: # At least the last point, if the list is not empty max_value = 1 for i inrange(len(points)): memo = {} for j inrange( i + 1 ,len(points)):
dx = points[i][0]-points[j][0] dy = points[i][1]-points[j][1]
if dx == 0: if ("#",-points[i][0]) in memo: memo[("#",-points[i][0])] += 1 else: memo[("#",-points[i][0])] = 2
else: tan = dy / dx res = points[i][1] - tan*points[i][0] if (tan , res) in memo: memo[(tan,res)] += 1 else: memo[(tan,res)] = 2 if memo: max_value = max(max_value , max(memo.values()))