55. Jump Game
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 39% Topics: Array, Dynamic Programming, Greedy
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(n)
# Space: O(1)
class Solution(object):
# @param A, a list of integers
# @return a boolean
def canJump(self, A):
reachable = 0
for i, length in enumerate(A):
if i > reachable:
break
reachable = max(reachable, i + length)
return reachable >= len(A) - 1
Solution from kamyu104/LeetCode-Solutions · MIT