Jump Game
Problem: Jump Game
We can just scan the whole array and if we cannot jump further at several consecutive positions, we cannot get to the end.
Code in Python:
class Solution(object):
def canJump(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
far = 0
for i in xrange(len(nums)):
if i > far:
return False
if i + nums[i] > far:
far = i + nums[i]
return True