We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 657e97c commit d32a082Copy full SHA for d32a082
jump_game_vi/src/lib.rs
@@ -2,6 +2,9 @@ pub struct Solution {}
2
3
impl Solution {
4
pub fn max_result(nums: Vec<i32>, k: i32) -> i32 {
5
+ //! 再优化,就需要用索引优先队列缓存索引 i 能跳到的最大值,
6
+ //! 即索引 (i + 1)..(i + 1 + k as usize).min(nums.len()) 中的最大值。
7
+ //! 这样可以不用每次都计算这个序列中的最大值
8
let mut max_cache = vec![0; nums.len()];
9
for (i, n) in nums.iter().enumerate().rev() {
10
let res_vec = max_cache[(i + 1)..(i + 1 + k as usize).min(nums.len())].to_vec();
0 commit comments