Skip to content

Commit b6c57f2

Browse files
committed
Time: 409 ms (29.51%), Space: 10.2 MB (70.29%) - LeetHub
1 parent b3977f3 commit b6c57f2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

204-count-primes/204-count-primes.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
class Solution {
22
public:
33
int countPrimes(int n) {
4+
45
int cnt = 0;
6+
57
vector<bool> prime(n+1, true);
68

79
prime[0] = prime[1] = false;
810

911
for(int i=2; i<n; i++){
1012

1113
if(prime[i]){
14+
1215
cnt++;
1316

1417
for(int j=2*i; j<n; j = j+i){
18+
1519
prime[j] = 0;
20+
1621
}
1722
}
1823

0 commit comments

Comments
 (0)