'Your Answer' inconsistent with output on my local machine


  • 0
    G

    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[0]).sum()
                nrInfs = np.isinf(freq[0]).sum()
                counts = nrNans if np.all(np.isnan(freq[0])) else max(np.max(freq[1]), 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.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.