Skip to content

Commit c20a0af

Browse files
committed
number-of-1-bits solution
1 parent 0fb50a8 commit c20a0af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

number-of-1-bits/yyyyyyyyyKim.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
answer = 0
4+
5+
while n > 0:
6+
answer += n%2 #나머지(현재 비트가 1이면 ++)
7+
n //= 2 #몫(다음 비트로 이동)
8+
9+
return answer

0 commit comments

Comments
 (0)