Skip to content

Commit 2ebc5a9

Browse files
committed
create jump game ii rust solution
1 parent 09cbb32 commit 2ebc5a9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

rust/0045-jump-game-ii.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
impl Solution {
2+
pub fn jump(nums: Vec<i32>) -> i32 {
3+
let mut res = 0;
4+
let mut l = 0;
5+
let mut r = 0;
6+
7+
while r < nums.len() - 1 {
8+
let mut max_jump = 0;
9+
for i in l..=r {
10+
max_jump = max_jump.max(i + nums[i] as usize);
11+
}
12+
13+
l = r + 1;
14+
r = max_jump;
15+
res += 1;
16+
}
17+
18+
return res;
19+
}
20+
}

0 commit comments

Comments
 (0)