LintCode Q116 Jump Game in Python

  • Jinhai ZHOU
  • 2 Minutes
  • 2017年1月12日
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution:
# @param A, a list of integers
# @return a boolean
def canJump(self, A):
# write your code here
current = 0
while current >=0 and current < len(A)-1:
max_jump = A[current]
while current + max_jump < len(A)-1 and A[current + max_jump] == 0:
max_jump -= 1
if max_jump == 0:
A[current] = 0
max_jump = -1
current += max_jump
if current >= len(A)-1:
return True
else:
return False
知识共享许可协议
本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。