Why the brute-force solution gets MemoryError?

  • 0
    class Solution(object):
    def myPow(self, x, n):
        :type x: float
        :type n: int
        :rtype: float
        for i in range(abs(n)):
        if n<0:
            return 1.0/mult
            return mult

    I am a new beginner for Python. I do know this solution is the most inefficient way, but I just want to know what does the error MemoryError mean?
    Thanks in advance.

  • 1

    range(n) returns an array: [0, 1, 2, ..., n-1]; it could be larger than the size of your computer's memory if n is big. Use xrange(n) instead.

Log in to reply

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