Skip to content

Commit 7508fad

Browse files
committed
Add solution #55
1 parent 0c9684a commit 7508fad

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
52|[N-Queens II](./0052-n-queens-ii.js)|Hard|
6161
53|[Maximum Subarray](./0053-maximum-subarray.js)|Easy|
6262
54|[Spiral Matrix](./0054-spiral-matrix.js)|Medium|
63+
55|[Jump Game](./0055-jump-game.js)|Medium|
6364
57|[Insert Interval](./0057-insert-interval.js)|Medium|
6465
58|[Length of Last Word](./0058-length-of-last-word.js)|Easy|
6566
59|[Spiral Matrix II](./0059-spiral-matrix-ii.js)|Medium|

solutions/0055-jump-game.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* 55. Jump Game
3+
* https://leetcode.com/problems/jump-game/
4+
* Difficulty: Medium
5+
*
6+
* You are given an integer array nums. You are initially positioned at the
7+
* array's first index, and each element in the array represents your maximum
8+
* jump length at that position.
9+
*
10+
* Return true if you can reach the last index, or false otherwise.
11+
*/
12+
13+
/**
14+
* @param {number[]} nums
15+
* @return {boolean}
16+
*/
17+
var canJump = function(nums) {
18+
let max = nums[0];
19+
20+
for (let i = 1; i < nums.length; i++) {
21+
if (max < i) {
22+
return false;
23+
}
24+
max = Math.max(nums[i] + i, max);
25+
}
26+
27+
return true;
28+
};

0 commit comments

Comments
 (0)