204. Count Primes
# Easy
要用一个特殊的方法来做会比较快。加速三部曲:
遍历数组,判断每个数是不是素数
遍历数组,判断每个数的时候,只除以[ 2, sqrt(n) ]区间的数看是否能整除即可
建一个一样大小的数组isPrime[n],初始化为true, 如果一个数是素数,则其倍数都是素数,直到遍历完所有数为止
Hightlight initilize an array with length of a variable:
Last updated
# Easy
要用一个特殊的方法来做会比较快。加速三部曲:
遍历数组,判断每个数是不是素数
遍历数组,判断每个数的时候,只除以[ 2, sqrt(n) ]区间的数看是否能整除即可
建一个一样大小的数组isPrime[n],初始化为true, 如果一个数是素数,则其倍数都是素数,直到遍历完所有数为止
Hightlight initilize an array with length of a variable:
Last updated