반응형
https://school.programmers.co.kr/learn/courses/30/lessons/12980
풀이
풀었는데 원리를 1도 모르겠다.....
역시 divmod를 사용하는 문제는 기본적을 이해하기가 어렵다...
def solution(n):
ans = 0
while True:
n, r= divmod(n, 2)
if (r == 1):
ans += 1
if (n == 0):
break
return ans
728x90
반응형
'코딩 테스트 > Programmers' 카테고리의 다른 글
[Python] [Level 2] 행렬의 곱셈 (0) | 2022.10.31 |
---|---|
[Python] [Level 2] H-Index (0) | 2022.10.29 |
[Python] [Level 2] 예상 대진표 (0) | 2022.10.27 |
[Python] [Level 2] N개의 최소공배수 (0) | 2022.10.22 |
[Python] [Level 2] 구명보트 (min과 max를 정하기) (0) | 2022.10.21 |