Skip to content

Commit f4b3dc4

Browse files
committed
4. Jump Game
1 parent 392aaf6 commit f4b3dc4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

jump-game/sunjae95.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @description
3+
*
4+
* n = length of nums
5+
* time complexity: O(n)
6+
* space complexity: O(1)
7+
*/
8+
var canJump = function (nums) {
9+
let cur = 1;
10+
for (const num of nums) {
11+
if (cur === 0) return false;
12+
cur--;
13+
cur = cur > num ? cur : num;
14+
}
15+
16+
return true;
17+
};

0 commit comments

Comments
 (0)