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 ee1ad8e commit 9e6d539Copy full SHA for 9e6d539
number-of-1-bits/hwanmini.js
@@ -0,0 +1,20 @@
1
+// 시간복잡도: O(log n)
2
+// 공간복잡도: O(log n)
3
+
4
+const replaceZeroToEmptyString = (str) => str.replaceAll('0','')
5
6
7
+/**
8
+ * @param {number} n
9
+ * @return {number}
10
+ */
11
+var hammingWeight = function(n) {
12
+ const binaryNum = n.toString(2)
13
+ const replacedNumber = replaceZeroToEmptyString(binaryNum)
14
+ return replacedNumber.length
15
+};
16
17
18
+console.log(hammingWeight(11));
19
+console.log(hammingWeight(128));
20
+console.log(hammingWeight(2147483645));
0 commit comments