The following solution returns
2 for the input
[[-635,462],[-444,47]] on my local machine. However, when I run the code on the webpage 'Your answer' displays
1. I don't understand why. It's the exact same code. I'd be very grateful for any help with this issue.
import numpy as np # 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 """ N = len(points) if N == 0: return 0 xs = np.array([p.x for p in points]) ys = np.array([p.y for p in points]) xsM = np.repeat(xs, N).reshape((N, N)) ysM = np.repeat(ys, N).reshape((N, N)) xDiff = xsM - xs yDiff = ysM - ys tmp = yDiff / xDiff maxCt = 0 for i in range(N): freq = np.unique(tmp[i], return_counts=True) nrNans = np.isnan(freq).sum() nrInfs = np.isinf(freq).sum() counts = nrNans if np.all(np.isnan(freq)) else max(np.max(freq), nrInfs) + nrNans if counts > maxCt: maxCt = counts return np.asscalar(maxCt)
Please note that I do not know whether this solution is correct or not. I expect a TLE.