Skip to content

Commit 47d1e92

Browse files
author
sejineer
committed
number-of-1-bits solution
1 parent f1ba297 commit 47d1e92

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

number-of-1-bits/sejineer.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
시간 복잡도: O(logN)
3+
공간 복잡도: O(1)
4+
"""
5+
class Solution:
6+
def hammingWeight(self, n: int) -> int:
7+
result = 1
8+
while n // 2 != 0:
9+
a = n // 2
10+
b = n % 2
11+
result += b
12+
n = a
13+
return result

0 commit comments

Comments
 (0)