python solution


  • 1
    Y
        def countPrimes(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n<=2:
                return 0
            isPrime=[1]*n
            isPrime[0]=0
            isPrime[1]=0
            for i in range(2,int(n**0.5)+1):
                for j in range(2,int(n/i)+1):
                    if i*j<n:
                        isPrime[i*j]=0
            return sum(isPrime)
    

Log in to reply
 

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