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 9add58e commit faae973Copy full SHA for faae973
204-count-primes.js
@@ -1,3 +1,28 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {number}
4
+ */
5
+const countPrimes = function(n) {
6
+ const arr = Array(n).fill(0)
7
+
8
+ for(let i = 2; i * i < n; i++) {
9
+ if(arr[i] !== 0) continue
10
+ let j = i * i
11
+ while(j < n) {
12
+ arr[j] = 1
13
+ j += i
14
+ }
15
16
17
+ let res = 0
18
+ for(let i = 2; i < n; i++) {
19
+ if(arr[i] === 0) res++
20
21
+ return res
22
+};
23
24
+// another
25
26
/**
27
* @param {number} n
28
* @return {number}
0 commit comments