Skip to content

Commit 2ae9f86

Browse files
committed
Add week 1 solutions: number-of-1-bits
1 parent ace8fba commit 2ae9f86

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

number-of-1-bits/gitsunmin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* https://leetcode.com/problems/number-of-1-bits/
3+
* time complexity : O(log n)
4+
* space complexity : O(log n)
5+
*/
6+
function hammingWeight(n: number): number {
7+
return n.toString(2).replaceAll('0', '').length
8+
}

0 commit comments

Comments
 (0)