mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-11 04:54:51 +08:00
Update 0045.跳跃游戏II.md
This commit is contained in:
@ -386,13 +386,13 @@ impl Solution {
|
||||
let mut cur_distance = 0;
|
||||
let mut ans = 0;
|
||||
let mut next_distance = 0;
|
||||
for (n, &i) in nums.iter().enumerate() {
|
||||
next_distance = (n as i32 + i).max(next_distance);
|
||||
for (i, &n) in nums.iter().enumerate().take(nums.len() - 1) {
|
||||
next_distance = (n as usize + i).max(next_distance);
|
||||
if i == cur_distance {
|
||||
if cur_distance < n as i32 - 1 {
|
||||
if cur_distance < nums.len() - 1 {
|
||||
ans += 1;
|
||||
cur_distance = next_distance;
|
||||
if next_distance >= n as i32 - 1 {
|
||||
if next_distance >= nums.len() - 1 {
|
||||
break;
|
||||
};
|
||||
} else {
|
||||
@ -403,7 +403,6 @@ impl Solution {
|
||||
ans
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
```Rust
|
||||
@ -416,8 +415,8 @@ impl Solution {
|
||||
let mut cur_distance = 0;
|
||||
let mut ans = 0;
|
||||
let mut next_distance = 0;
|
||||
for (n, &i) in nums.iter().enumerate() {
|
||||
next_distance = (n as i32 + i).max(next_distance);
|
||||
for (i, &n) in nums.iter().enumerate().take(nums.len() - 1) {
|
||||
next_distance = (n as usize + i).max(next_distance);
|
||||
if i == cur_distance {
|
||||
cur_distance = next_distance;
|
||||
ans += 1;
|
||||
@ -426,7 +425,6 @@ impl Solution {
|
||||
ans
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user