34 lines
912 B
Python
34 lines
912 B
Python
def canJump(nums):
|
|
"""
|
|
:type nums: List[int]
|
|
:rtype: bool
|
|
"""
|
|
# Each index value is the maximum you can jump from that position
|
|
# count = 1
|
|
# for x in nums:
|
|
# if x >= len(nums)-1:
|
|
# return True
|
|
# jump = nums[count]
|
|
# if x >= jump:
|
|
# if jump >= len(nums)-1:
|
|
# return True
|
|
maxJump = 0
|
|
for x in range(len(nums)-1):
|
|
maxJump += nums[x]
|
|
print(maxJump)
|
|
if nums[x] == 0:
|
|
return False
|
|
if maxJump >= len(nums)-1:
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
|
|
# jump = nums[1]
|
|
# if jump >= len(nums)-1:
|
|
# print('Can make the jump')
|
|
# return True
|
|
# else:
|
|
# return False
|
|
print(canJump([2,3,1,1,4]))
|
|
print(canJump([3,2,1,0,4])) |