mirror of
https://github.com/ShusenTang/LeetCode.git
synced 2024-09-02 14:20:01 +00:00
update code2
This commit is contained in:
parent
8de5761fc3
commit
d75905bfbe
@ -37,14 +37,15 @@ public:
|
||||
class Solution {
|
||||
public:
|
||||
int countPrimes(int n) {
|
||||
vector<unsigned int>nums(n, 1); // 0代表被划去,1代表没被划去
|
||||
int count = 0;
|
||||
vector<bool>Prime(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;
|
||||
}
|
||||
};
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user