Created
February 26, 2018 15:19
-
-
Save s4553711/771cee8309eeeebfa51f1f7631192ff2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution { | |
public: | |
int countPrimes(int n) { | |
if (n == 1 || n == 0) return 0; | |
vector<bool> passed(n, true); | |
passed[0] = false, passed[1] = false; | |
for(int i = 0; i < sqrt(n); i++) { | |
if (passed[i]) { | |
for(int j = i * i; j < n; j += i) { | |
passed[j] = false; | |
} | |
} | |
} | |
return count(passed.begin(), passed.end(), true); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment