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 fc21467 commit 20df14dCopy full SHA for 20df14d
45.跳跃游戏-ii.js
@@ -0,0 +1,27 @@
1
+/*
2
+ * @lc app=leetcode.cn id=45 lang=javascript
3
+ *
4
+ * [45] 跳跃游戏 II
5
6
+ * 1. 贪心问题, 对于每轮跳跃操作, 找到当前能跳到最远的位置
7
+ */
8
+
9
+// @lc code=start
10
+/**
11
+ * @param {number[]} nums
12
+ * @return {number}
13
14
+var jump = function(nums) {
15
+ let end = 0;
16
+ let max = 0;
17
+ let step = 0;
18
+ for (let i = 0; i < nums.length - 1; i++) {
19
+ max = Math.max(max, i + nums[i]);
20
+ if (i === end) {
21
+ end = max;
22
+ step++;
23
+ }
24
25
+ return step;
26
+};
27
+// @lc code=end
0 commit comments