passes 137/172 test cases

This commit is contained in:
Jacob Delgado 2023-07-01 19:39:11 -07:00
parent 2a6b73a842
commit 262543afc5

View File

@ -0,0 +1,34 @@
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]))