204. Count Primes
题目描述:Description:
Count the number of prime numbers less than a non-negative number, n.
题目大意:找出小于n的素数的个数。
代码:
package HashTable; /** * @author OovEver * 2018/1/12 21:59 */ public class LeetCode204 { public int countPrimes(int n) { boolean[] notprims = new boolean[n]; int count = 0; for(int i=2;i<n;i++) { if (notprims[i] == false) { count++; for(int j=2;i*j<n;j++) { notprims[i * j] = true; } } } return count; } }