Skip to content

Commit 216fbcb

Browse files
committed
number of 1 bits
1 parent e645851 commit 216fbcb

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

number-of-1-bits/changhyumm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
count = 0
4+
# 시간복잡도 O(log n) 반으로 나누기 때문
5+
while n > 0:
6+
if n % 2 == 1:
7+
count += 1
8+
n = n // 2
9+
else:
10+
n = n / 2
11+
return count

0 commit comments

Comments
 (0)