Skip to content

Commit 6d9e162

Browse files
authored
Create Solution.js
1 parent fc6e992 commit 6d9e162

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {number}
4+
*/
5+
var jump = function(nums) {
6+
let jumps = 0;
7+
let currentEnd = 0;
8+
let farthest = 0;
9+
10+
for (let i = 0; i < nums.length - 1; i++) {
11+
farthest = Math.max(farthest, i + nums[i]);
12+
13+
if (i === currentEnd) {
14+
jumps++;
15+
currentEnd = farthest;
16+
}
17+
}
18+
19+
return jumps;
20+
};

0 commit comments

Comments
 (0)