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 4ed4d3c commit 205eb5dCopy full SHA for 205eb5d
counting-bits/hyejjun.js
@@ -0,0 +1,26 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {number[]}
4
+ */
5
+var countBits = function (n) {
6
+
7
+ let result = [];
8
9
+ for (let i = 0; i <= n; i++) {
10
11
+ let binary = i.toString(2);
12
+ let sum = 0;
13
14
+ for (let char of binary) {
15
+ sum += Number(char);
16
+ }
17
+ result.push(sum);
18
19
20
+ return result;
21
22
+};
23
24
25
+console.log(countBits(2));
26
+console.log(countBits(5));
0 commit comments