We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2468b9a commit ad5b1ebCopy full SHA for ad5b1eb
1696-jump-game-vi.js
@@ -3,21 +3,20 @@
3
* @param {number} k
4
* @return {number}
5
*/
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);
+const maxResult = function (nums, k) {
+ const n = nums.length
+ const f = Array(n).fill(0)
+ f[0] = nums[0]
+ const q = [0]
+ for (let i = 1; i < n; ++i) {
+ while (i - q[0] > k) {
+ q.shift()
20
}
21
- return f[n - 1];
22
-};
23
-
+ f[i] = f[q[0]] + nums[i]
+ while (q.length && f[i] >= f[q[q.length - 1]]) {
+ q.pop()
+ }
+ q.push(i)
+ return f[n - 1]
+}
0 commit comments