parent
db785168ba
commit
815446cc13
|
|
@ -175,7 +175,22 @@ class Solution {
|
||||||
```
|
```
|
||||||
|
|
||||||
Python:
|
Python:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def jump(self, nums: List[int]) -> int:
|
||||||
|
if len(nums) == 1: return 0
|
||||||
|
ans = 0
|
||||||
|
curDistance = 0
|
||||||
|
nextDistance = 0
|
||||||
|
for i in range(len(nums)):
|
||||||
|
nextDistance = max(i + nums[i], nextDistance)
|
||||||
|
if i == curDistance:
|
||||||
|
if curDistance != len(nums) - 1:
|
||||||
|
ans += 1
|
||||||
|
curDistance = nextDistance
|
||||||
|
if nextDistance >= len(nums) - 1: break
|
||||||
|
return ans
|
||||||
|
```
|
||||||
|
|
||||||
Go:
|
Go:
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue