标签:
Description:
Count the number of prime numbers less than a non-negative number, n.
Credits:
Special thanks to @mithmatt for adding this problem and creating all test cases.
本题的思路分为以下几步:
class Solution(object): def countPrimes(self, n): """ :type n: int :rtype: int """ if n <=2: return 0 Prime = [True]*n Prime[0],Prime[1] = False,False for i in range(2,int(n**0.5)+1): if Prime[i]: Prime[i*i:n:i] = [False]*len(Prime[i*i:n:i]) return sum(Prime)
标签:
原文地址:http://www.cnblogs.com/winnie-daddy/p/5597350.html