Skip to content

Commit c382ca0

Browse files
Merge pull request youngyangyang04#1944 from fwqaaq/patch-10
Update 0055.跳跃游戏.md 优化 rust
2 parents 8b9f29a + 3d64ead commit c382ca0

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

problems/0055.跳跃游戏.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,16 @@ var canJump = function(nums) {
178178

179179
```Rust
180180
impl Solution {
181-
fn max(a: usize, b: usize) -> usize {
182-
if a > b { a } else { b }
183-
}
184181
pub fn can_jump(nums: Vec<i32>) -> bool {
185-
let mut cover = 0;
186-
if (nums.len() == 1) { return true; }
187-
let mut i = 0;
182+
if nums.len() == 1 {
183+
return true;
184+
}
185+
let (mut i, mut cover) = (0, 0);
188186
while i <= cover {
189-
cover = Self::max(i + nums[i] as usize, cover);
190-
if cover >= nums.len() - 1 { return true; }
187+
cover = (i + nums[i] as usize).max(cover);
188+
if cover >= nums.len() - 1 {
189+
return true;
190+
}
191191
i += 1;
192192
}
193193
false

0 commit comments

Comments
 (0)