Skip to content

Commit fb856a1

Browse files
committed
feat: resolved without cache
1 parent fdced4f commit fb856a1

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

jump_game_vi/src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
11
pub struct Solution {}
22

33
impl Solution {
4-
pub fn max_result(nums: Vec<i32>, k: i32) -> i32 {}
4+
fn max_res(nums: &Vec<i32>, i: usize, k: usize) -> i32 {
5+
if i >= nums.len() {
6+
return 0;
7+
}
8+
nums[i]
9+
+ (1..=k)
10+
.map(|x| Self::max_res(nums, i + x, k))
11+
.max()
12+
.unwrap()
13+
}
14+
15+
pub fn max_result(nums: Vec<i32>, k: i32) -> i32 {
16+
Self::max_res(&nums, 0, k as usize)
17+
}
518
}
619

720
#[cfg(test)]

0 commit comments

Comments
 (0)