Update 0045.跳跃游戏II.md

增加python -  贪心版本三 - 类似‘55-跳跃游戏’写法
This commit is contained in:
ZerenZhang2022 2023-04-06 15:48:47 -04:00 committed by GitHub
parent 2ff490eb2f
commit 700b5c388b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -231,6 +231,21 @@ class Solution:
step += 1
return step
```
```python
# 贪心版本三 - 类似55-跳跃游戏’写法
class Solution:
def jump(self, nums) -> int:
if len(nums)==1: return 0
i = 0
count = 0
cover = 0
while i<=cover:
for i in range(i,cover+1):
cover = max(nums[i]+i,cover)
if cover>=len(nums)-1: return count+1
count+=1
```
```python
# 动态规划做法