Skip to content

Commit 637ca7d

Browse files
committed
Number of 1 bits solution
1 parent 3e593f4 commit 637ca7d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

number-of-1-bits/ohkingtaek.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from collections import Counter
2+
3+
class Solution:
4+
def hammingWeight(self, n: int) -> int:
5+
"""
6+
- 시간복잡도: O(n)
7+
- 공간복잡도: O(n)
8+
문자열을 이진수로 변환하고, 1의 개수를 세기
9+
"""
10+
return Counter(bin(n)[2:])["1"]

0 commit comments

Comments
 (0)