-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjump.py
More file actions
43 lines (40 loc) · 764 Bytes
/
jump.py
File metadata and controls
43 lines (40 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
n = len(A)
maxi = 0
i = 0
jump = 0
visit = [0 for i in range(n)]
while maxi < n:
maxi = A[i] + i
if maxi < n:
visit[maxi] += 1
if visit[maxi] > 5:
return -1
i = maxi
jump += 1
return jump
"""
pawn = A[0]
i = 0
dist = pawn + i
"""
"""
jump = 0
sumi = A[0]
while sumi < n:
i = sumi
sumi = i + A[i]
i += 1
jump += 1
return jump
"""
"""
while dist < n:
i = dist
jump += 1
dist = A[i] + i
return jump+1
"""