Jump Game

 

55. Jump Game

Solution

  1. Always check if we can arrive at the next position,i.e. curr >= idx.
  2. Keep the furthest position we can approach.
  3. If we can always approach the next position and the furthest approachable is further than the last position, then can jump.
    def canJump(self, nums):
     """
     :type nums: List[int]
     :rtype: bool
     """
     curr = 0
     for idx, num in enumerate(nums):
         if curr < idx:
             return False
         reachable = num + idx
         curr = max(curr, reachable)
     return len(nums) - 1 <= curr