Skip to content

Commit a3ce78a

Browse files
committed
[PGS] 점프와 순간이동 / Level 2 / 30분 / 성공
1 parent c6c42c2 commit a3ce78a

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
풀이1
3+
"""
4+
def solution(n):
5+
"""
6+
이동방법
7+
1. K칸 앞으로 점프 => 건전지 사용량 -K
8+
2. 순간이동: (현재까지 온 거리) * 2 => 건전지 사용량 X
9+
목표
10+
- 거리가 N만큼 떨어져있는 장소로 간다고 했을 때 건전지 사용량의 최솟값을 구하기
11+
"""
12+
ans = 0
13+
while n > 0:
14+
if (n % 2 == 0):
15+
n //= 2
16+
else:
17+
n -= 1
18+
ans += 1
19+
return ans
20+
21+
"""
22+
풀이2
23+
"""
24+
def solution(n):
25+
return bin(n).count('1')

0 commit comments

Comments
 (0)