We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 737b202 commit b8b94a3Copy full SHA for b8b94a3
number-of-1-bits/unpo88.py
@@ -0,0 +1,24 @@
1
+class Solution:
2
+ def hammingWeight(self, n: int) -> int:
3
+ return bin(n).count('1')
4
+
5
6
+"""
7
+================================================================================
8
+풀이 과정
9
10
11
+1. 일단 이진법으로 변경이 필요하고
12
+2. 변경된 이진법에서 1을 카운팅해야하네?
13
14
15
+[1차 시도] 내장 함수 활용
16
+────────────────────────────────────────────────────────────────────────────────
17
+3. Python의 bin() 함수로 이진 문자열 변환
18
+4. count() 메서드로 '1' 문자 개수 세기
19
20
21
22
+5. 시간 복잡도: O(log n) - 이진 표현의 비트 수만큼
23
+6. 공간 복잡도: O(log n) - 이진 문자열 생성
24
0 commit comments