input :
output :
조건 :
Solution explain : Solution1
class Solution:
def jump(self, nums: List[int]) -> int:
length = len(nums)
dp = [float("inf")] * length
dp[0] = 0
for idx in range(length):
num_range = nums[idx]
for step in range(1, num_range + 1):
if idx + step >= length:
continue
dp[idx + step] = min(dp[idx] + 1, dp[idx + step])
return dp[-1]
class Solution:
def jump(self, nums: List[int]) -> int:
length = len(nums)
dp = [float("inf")] * length
dp[0] = 0
for idx in range(length):
num_range = nums[idx]
for step in range(1, num_range + 1):
if idx + step >= length:
continue
dp[idx + step] = min(dp[idx] + 1, dp[idx + step])
return dp[-1]