-
Notifications
You must be signed in to change notification settings - Fork 24
/
lib.rs
40 lines (37 loc) · 837 Bytes
/
lib.rs
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
32
33
34
35
36
37
38
39
40
/*
* @lc app=leetcode.cn id=55 lang=rust
*
* [55] 跳跃游戏
*/
struct Solution {}
// @lc code=start
impl Solution {
pub fn can_jump(nums: Vec<i32>) -> bool {
let n = nums.len();
let mut dp = vec![false; n];
dp[0] = true;
for i in 1..nums.len() {
for j in 0..i {
dp[i] = if dp[j] && nums[j] >= (i - j) as i32 {
true
} else {
false
};
if dp[i] {
break;
}
}
}
return dp[n - 1];
}
}
// @lc code=end
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn name() {
println!("{:?}", Solution::can_jump(vec![2, 3, 1, 1, 4]));
println!("{:?}", Solution::can_jump(vec![3, 2, 1, 0, 4]))
}
}