Python in count primes Can anybody help me fix Memory Limit Exceeded?

  • 0
    class Solution(object):
        blank = 0
        def countPrimes(self, n):
            global blank
            blank = 0
            if n < 2:
                return blank-1
            for i in range(2,n):
                if (n%i)==0:
                    return self.countPrimes(n-1)
                return self.countPrimes(n-1)

  • 0

    Use xrange instead of range. Though that will only fix your memory limit issue, not the other issues, and when you fix those, you likely won't need to use xrange. But it's good to know the difference anyway.

Log in to reply

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