本文共 510 字,大约阅读时间需要 1 分钟。
Count Primes
Description:
Count the number of prime numbers less than a non-negative number, n
Java代码:public class Solution { public int countPrimes(int n) { boolean[] exist = new boolean[n]; Arrays.fill(exist, true); int count = 0; for (int i = 2; i < n; i++) { if (exist[i]) { count++; for (int j = 2; i * j < n; j++) { exist[i*j] = false; } } } return count; }}
转载地址:http://vvuni.baihongyu.com/