Skip to content

Commit

Permalink
Added alternative solution for jump game
Browse files Browse the repository at this point in the history
  • Loading branch information
shichao-an committed Jun 14, 2014
1 parent 0bcc46b commit 7fb6cbf
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions jump_game/solution2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
# @param A, a list of integers
# @return a boolean
def canJump(self, A):
n = len(A)
if n == 1:
return True
d = [i + A[i] for i in range(n)]
reach = n - 1
for i in range(1, n):
j = n - 1 - i
if d[j] >= reach:
reach = j
return reach == 0

0 comments on commit 7fb6cbf

Please sign in to comment.