leetcode Count Primes

来源:互联网 发布:淘宝网网站注册支付宝 编辑:程序博客网 时间:2024/05/10 03:36

筛法求素数。没啥大不了的

import java.util.Arrays;public class Solution {    public  int countPrimes(int n) {        int[] array=new int[n];        Arrays.fill(array, 1);        int count=0;        for(int i=2;i<n;i++)        {        if(array[i]==1)        {        count++;        int j=1;        while(i*j<n)        {        array[i*j]=2;        j++;        }        }                }        return count;    }}


0 0
原创粉丝点击