LC055 - Jump Game
Problem
Example
Solution
Naive
Greedy
def canJump(self, nums: List[int]) -> bool:
# target is the index of the last element
target = len(nums) - 1
for i in range(len(nums)-1, -1, -1):
if i + nums[i] >= target:
target = i
if target == 0:
return True
return FalseLast updated