204. Count Primes

来源:互联网 发布:python 核密度估计 编辑:程序博客网 时间:2024/05/03 22:38

题目:https://leetcode.com/problems/count-primes/

代码:

public class Solution {    public int countPrimes(int n) {        if(n<3)            return 0;        boolean[] notprime = new boolean[n];        int result = 0;        for(int i=2;i<n;i++)        {            if(notprime[i])                continue;            for(int k=2;k*i<n;k++)                notprime[k*i] = true;            result++;        }        return result;    }}
0 0
原创粉丝点击