-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path45.py
30 lines (30 loc) · 1.04 KB
/
45.py
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
__________________________________________________________________________________________________
sample 36 ms submission
class Solution:
def jump(self, nums: List[int]) -> int:
step = 0
curr = 0
next = 0
n = len(nums)
for i in range(0,n):
if curr<i:
curr = next
step += 1
next = max(next, nums[i]+i)
return step
__________________________________________________________________________________________________
sample 14096 kb submission
class Solution:
def jump(self, nums: List[int]) -> int:
start, end, step = 0, 0, 0
while end < len(nums)-1:
step += 1
maxend = end
for i in range(start, end+1):
tmp = i + nums[i]
if tmp > maxend:
maxend = tmp
start, end = end+1, max(maxend,end)
print(start,end)
return step
__________________________________________________________________________________________________