Skip to content

Commit 5168b04

Browse files
committed
Feat: 55. Jump Game
1 parent abe7cc5 commit 5168b04

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

jump-game/HC-kang.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* https://leetcode.com/problems/jump-game/
3+
* T.C. O(n)
4+
* S.C. O(1)
5+
*/
6+
function canJump(nums: number[]): boolean {
7+
let max = 0;
8+
9+
for (let i = 0; i < nums.length; i++) {
10+
if (i > max) return false;
11+
max = Math.max(max, i + nums[i]);
12+
if (max >= nums.length) return true;
13+
}
14+
15+
return false;
16+
}

0 commit comments

Comments
 (0)