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 9951e38 commit a423c0cCopy full SHA for a423c0c
number-of-1-bits/lhc0506.js
@@ -0,0 +1,10 @@
1
+/**
2
+ * @param {number} n
3
+ * @return {number}
4
+ */
5
+var hammingWeight = function(n) {
6
+ return [...(n).toString(2)].reduce((acc, cur) => cur === '1' ? acc + 1 : acc, 0);
7
+};
8
+
9
+//시간 복잡도 : O(logn)
10
+//공간 복잡도 : O(logn)
0 commit comments