Skip to content

Commit 5e9e36b

Browse files
committed
Jump Game Solution
1 parent fa0b9b0 commit 5e9e36b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

jump-game/clara-shin.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number[]} nums
3+
* @return {boolean}
4+
*/
5+
var canJump = function (nums) {
6+
let farthest = 0;
7+
8+
for (let i = 0; i < nums.length; i++) {
9+
// 현재 위치가 지금까지 갈 수 있는 가장 먼 거리보다 멀다면
10+
if (i > farthest) {
11+
return false; // 도달 불가능
12+
}
13+
14+
// 현재 위치에서 갈 수 있는 가장 먼 거리 업데이트
15+
farthest = Math.max(farthest, i + nums[i]);
16+
}
17+
18+
return true;
19+
};

0 commit comments

Comments
 (0)