We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d611f7 commit cc5fc8cCopy full SHA for cc5fc8c
countPrimes.java
@@ -0,0 +1,24 @@
1
+class Solution {
2
+ public int countPrimes(int n) {
3
+ if(n<2){
4
+ return 0 ;
5
+ }
6
+ boolean isPrime[] = new boolean[n+1];
7
+ Arrays.fill(isPrime , true);
8
+ isPrime[0] = false;
9
+ isPrime[1] = false;
10
+ for(int i=2 ; i*i<=n ; i++){
11
+ for(int j = 2*i;j<=n;j+=i){
12
+ isPrime[j] = false;
13
14
15
+ int count=0;
16
+ for(int i=0;i<n;i++){
17
+ if(isPrime[i]==true){
18
+ count++;
19
20
21
+ return count;
22
23
+}
24
+
0 commit comments