Skip to content

Commit e0ae448

Browse files
committed
number-of-1-bits solution
1 parent f74db69 commit e0ae448

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

number-of-1-bits/sun912.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
TC: O(log n)
3+
SC: O(1)
4+
"""
5+
6+
class Solution:
7+
def hammingWeight(self, n: int) -> int:
8+
result = 0
9+
while n > 0:
10+
result += n % 2
11+
n = n//2
12+
13+
return result

0 commit comments

Comments
 (0)