Do python in leetcode support numpy? Why I cannot import numpy as np? Always a compile error.


  • 1
    Q

    the code is working fine at my machine, but get a compile error in leetcode

    # Definition for a point
    

    class Point:

    def init(self, a=0, b=0):

    self.x = a

    self.y = b

    import numpy as np
    class Solution:
    # @param points, a list of Points
    # @return an integer

    def maxPoints(self, points):
        l = len(points)
        maxv = 0
        m = 0
        vx = []
        vy = []
        vz = []
        for i in range(l-1):
            for j in range(i+1,l):
                vx.append(points[i].x-points[j].x)
                vy.append(points[i].y-points[j].y)
                if points[i].x-points[j].x==0:
                    vz.append(' ')
                else:
                    vz.append((points[j].y*points[i].x-points[i].y*points[j].x)/(points[i].x-points[j].x))
                m = m+1
        for i in range(m-1):
            num = 1
            for j in range(i+1,m):
                if (np.mod(vx[j],vx[i])==np.mod(vy[j],vy[i])):
                    if vz[i]==vz[j]:
                        num = num + 1
            if num > maxv:
                maxv = num
        maxv = (1+np.sqrt(1+8*maxv))/2
        return maxv

  • 0
    S

    Import anything in python is forbidden in LeetCode.

    We will consider import numpy later or not. However, we will update about it.

    However, It would be better to use something else instead for now.


Log in to reply
 

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