-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.rs
More file actions
31 lines (26 loc) · 741 Bytes
/
main.rs
File metadata and controls
31 lines (26 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
fn main() {
println!("Hello, world!");
}
struct Solution {}
impl Solution {
pub fn can_jump(nums: Vec<i32>) -> bool {
let mut long = 0;
let nums: Vec<usize> = nums.into_iter().map(|x| x as usize).collect();
for i in 0..nums.len() {
if i + nums[i] > long { long = i + nums[i] }
if long >= nums.len() - 1 { return true }
if nums[i] == 0 && i == long { return false }
}
unimplemented!()
}
}
#[cfg(test)]
mod test {
use crate::*;
#[test]
fn basic() {
assert_eq!(Solution::can_jump(vec![2,3,1,1,4]), true);
assert_eq!(Solution::can_jump(vec![3,2,1,0,4]), false);
assert_eq!(Solution::can_jump(vec![0]), true);
}
}