204. Count Primes

class Solution {
public int countPrimes(int n) {
int count = 0;
for (int i = 2; i < n; i++){
if (isPrime(i)) count++;
}
return count;
}
public boolean isPrime(int n){
for (int i = 2; i*i <= n; i++){
if ( n % i == 0) return false;
}
return true;
}
}

### Like this:

Like Loading...

*Related*