Skip to content

Commit a423c0c

Browse files
author
이호찬
committed
number-of-1-bits solution
1 parent 9951e38 commit a423c0c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

number-of-1-bits/lhc0506.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)