Skip to content

Commit 869b211

Browse files
committed
jump game solution
1 parent 43effe9 commit 869b211

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

jump-game/hyer0705.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function canJump(nums: number[]): boolean {
2+
const n = nums.length;
3+
4+
let maximumReach = 0;
5+
6+
for (let i = 0; i < n; i++) {
7+
if (i > maximumReach) return false;
8+
9+
maximumReach = Math.max(maximumReach, i + nums[i]);
10+
}
11+
12+
return maximumReach >= n - 1;
13+
}

0 commit comments

Comments
 (0)