204. Count Primes
Count the number of prime numbers less than a non-negative number, n.
借鉴大佬的代码
class Solution {
public int countPrimes(int n) {
boolean[] notPrime=new boolean[n];
int count=0;
for(int i=2;i<n;i++){
if(notPrime[i]==false) {
count++;
for(int j=i;j<n;j+=i) {
notPrime[j]=true;
}
}
}
return count;
}
}