【LeetCode】 204. Count Primes

来源:互联网 发布:互联网it服务 编辑:程序博客网 时间:2024/05/22 10:58

Description:

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

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


0 0