This answer is based on this brilliant solution Fast Python Solution
I found there is still room to improve it.
Use 1, 0 instead of True, False, it could be a little faster.
class Solution: def countPrimes(self, n): """ :type n: int :rtype: int """ if n < 2: return 0 s =  * n s = s = 0 for i in range(2, int(n ** 0.5) + 1): if s[i] == 1: s[i * i:n:i] =  * len(s[i * i:n:i]) return sum(s)
Here is my submisson result
Here is the time analysis and comparision