Guest User

Untitled

a guest
Nov 17th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. # Python3
  2.  
  3. class Solution:
  4. def canJump(self, nums):
  5. """
  6. :type nums: List[int]
  7. :rtype: bool
  8. """
  9.  
  10. # approach: use dynamic programming to sequentialy check avaliability
  11.  
  12. n = len(nums)
  13. if n <= 1:
  14. return True
  15.  
  16. dp = [True] + [False] * (n - 1)
  17. for i in range(1, n):
  18. dp[i] = any(nums[j] >= (i - j) for j in range(i) if dp[j])
  19.  
  20. return dp[n - 1]
Add Comment
Please, Sign In to add comment