passes 137/172 test cases
This commit is contained in:
parent
2a6b73a842
commit
262543afc5
34
Top150Interview/55JumpGame.py
Normal file
34
Top150Interview/55JumpGame.py
Normal 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]))
|
||||||
Loading…
Reference in New Issue
Block a user