Skip to content

Commit ad5b1eb

Browse files
authored
Update 1696-jump-game-vi.js
1 parent 2468b9a commit ad5b1eb

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

1696-jump-game-vi.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@
33
* @param {number} k
44
* @return {number}
55
*/
6-
const maxResult = function(nums, k) {
7-
const n = nums.length;
8-
const f = Array(n).fill(0);
9-
f[0] = nums[0];
10-
const q = [0];
11-
for (let i = 1; i < n; ++i) {
12-
while (i - q[0] > k) {
13-
q.shift();
14-
}
15-
f[i] = f[q[0]] + nums[i];
16-
while (q.length && f[i] >= f[q[q.length - 1]]) {
17-
q.pop();
18-
}
19-
q.push(i);
6+
const maxResult = function (nums, k) {
7+
const n = nums.length
8+
const f = Array(n).fill(0)
9+
f[0] = nums[0]
10+
const q = [0]
11+
for (let i = 1; i < n; ++i) {
12+
while (i - q[0] > k) {
13+
q.shift()
2014
}
21-
return f[n - 1];
22-
};
23-
15+
f[i] = f[q[0]] + nums[i]
16+
while (q.length && f[i] >= f[q[q.length - 1]]) {
17+
q.pop()
18+
}
19+
q.push(i)
20+
}
21+
return f[n - 1]
22+
}

0 commit comments

Comments
 (0)