Skip to content

Commit 0325aaf

Browse files
committed
[PGS] 점프와 순간이동 / Level 2 / 25분 /성공
1 parent 074eda7 commit 0325aaf

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def solution(n):
2+
ans = 0
3+
4+
while n > 0:
5+
if n % 2 == 0:
6+
n //= 2
7+
else:
8+
n -= 1
9+
ans += 1
10+
11+
return ans
12+
13+
'''
14+
# 다른 풀이:
15+
def solution(n):
16+
return bin(n).count('1')
17+
'''

0 commit comments

Comments
 (0)