Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public int countPrimes(int n) { int count = 0; boolean[] f = new boolean[n]; for (int i = 2; i < n; i++) { if(!f[i]){ for (int j = 2; j*i < n; j++) { f[j*i] = true; } count++; } } return count; }

public int countPrimes(int n) { boolean[] notPrimes = new boolean[n]; notPrimes[0] = true; notPrimes[1] = true; int count = 0 ; for(int i = 2 ; i < n && !notPrimes[i] ; i++){ count++; for(int j = 2 ; i * j < n ; j++){ notPrimes[i*j] = true; } } return count; }```

@saneGuy why n<3 return 0, 2 not is primes?

@363655707 changed it ...

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.