Skip to content

Commit da3aad9

Browse files
committed
number of 1 bits solution
1 parent 4b09054 commit da3aad9

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

number-of-1-bits/yuseok89.py

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

0 commit comments

Comments
 (0)