Skip to content

Commit d32a082

Browse files
committed
feat: add refine strategy
1 parent 657e97c commit d32a082

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

jump_game_vi/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ pub struct Solution {}
22

33
impl Solution {
44
pub fn max_result(nums: Vec<i32>, k: i32) -> i32 {
5+
//! 再优化,就需要用索引优先队列缓存索引 i 能跳到的最大值,
6+
//! 即索引 (i + 1)..(i + 1 + k as usize).min(nums.len()) 中的最大值。
7+
//! 这样可以不用每次都计算这个序列中的最大值
58
let mut max_cache = vec![0; nums.len()];
69
for (i, n) in nums.iter().enumerate().rev() {
710
let res_vec = max_cache[(i + 1)..(i + 1 + k as usize).min(nums.len())].to_vec();

0 commit comments

Comments
 (0)