We have met ii already, so this will be easier. Just go from head, subtract 1 per step or gain a jump.
Solution:
# T:O(n) S:O(1)
class Solution:
# @param A, a list of integers
# @return a boolean
def canJump(self, A):
step = A[0]
for i in range(1, len(A)):
if step > 0:
step -= 1
step = max(step, A[i])
else:
return False
return True
Run Time: 72 ms
No comments:
Post a Comment