From d75905bfbe517721442b867eaac6e4181f36bfef Mon Sep 17 00:00:00 2001 From: ShusenTang Date: Sat, 4 Jul 2020 20:04:42 +0800 Subject: [PATCH] update code2 --- solutions/204. Count Primes.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/solutions/204. Count Primes.md b/solutions/204. Count Primes.md index 3e414d4..470c96f 100644 --- a/solutions/204. Count Primes.md +++ b/solutions/204. Count Primes.md @@ -37,14 +37,15 @@ public: class Solution { public: int countPrimes(int n) { - vectornums(n, 1); // 0代表被划去,1代表没被划去 - int count = 0; + vectorPrime(n + 1, true); + int res = 0; for(int i = 2; i < n; i++){ - if(nums[i] == 0) continue; - count++; - for(int j = 2; j * i < n; j++) nums[j * i] = 0; + if(Prime[i]){ + res++; + for(int j = i; j <= n / i; j++) Prime[i*j] = false; + } } - return count; + return res; } }; ```