LeetCode :Count Primes

来源:互联网 发布:房地产网络销售怎么样 编辑:程序博客网 时间:2024/05/22 00:48

Description:

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

class Solution {public:    int countPrimes(int n) {        int count = 0;        int *a = new int[n]();        if(n<2)           return 0;        for(int i=2;i<n;++i){            if(a[i]==0)            {                count++;                for(int j=2;i*j<n;++j){                    a[i*j] = 1;                }            }        }         return count;    }};
0 0