204. Count Primes

来源:互联网 发布:企业仓库软件 编辑:程序博客网 时间:2024/05/16 14:09

Description:

Count the number of prime numbers less than a non-negative number, n.


官方代码:

public 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 = 2; i*j < n; j++) {                    notPrime[i*j] = true;                }            }        }                return count;    }}

原创粉丝点击