Memory Limited Exceed


  • 0
    L
    class Solution:
    # @param {integer} n
    # @return {integer}
    def countPrimes(self, n):
        flag = [True for i in range(n)]
        base = 2
        while base * base < n:
            i = 2
            while i * base < n:
                flag[i*base] = False
                i += 1
            base += 1
            while flag[base] == False and base * base < n:
                base += 1
        res = 0
        for i in range(2, n):
            if flag[i]:
               res += 1
        return res
    

    Could anyone tell me why my code is memory limited exceed, and I just follow the hint.
    Many thanks!


  • 0
    T

    in python boolean is actually an int. My guess is a list of int is too slow for this problem.


Log in to reply
 

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