Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Python3
- class Solution:
- def canJump(self, nums):
- """
- :type nums: List[int]
- :rtype: bool
- """
- # approach: use dynamic programming to sequentialy check avaliability
- n = len(nums)
- if n <= 1:
- return True
- dp = [True] + [False] * (n - 1)
- for i in range(1, n):
- dp[i] = any(nums[j] >= (i - j) for j in range(i) if dp[j])
- return dp[n - 1]
Add Comment
Please, Sign In to add comment