링크
You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that position.
Return true if you can reach the last index, or false otherwise.
def canJump(self, nums: List[int]) -> bool:
n = len(nums)
dp = [False] * n
dp[0] = True
for i in range(n- 1):
if dp[i]:
for step in range(1, nums[i] + 1):
if i + step == n - 1: return True
if i + step < n: dp[i + step] = True
return dp[-1]
def canJump(self, nums):
m = 0
for i in range(len(nums)):
if i > m:
return False
m = max(m, i + nums[i])
return True
def canJump(self, nums: List[int]) -> bool:
debit = 0
for i in reversed(nums[:-1]):
debit += 1
if i - debit >= 0:
debit = 0
return debit == 0