Skip to content

Commit 1744c14

Browse files
committed
feat: Upload jump-game (typescript)
1 parent 04e55ea commit 1744c14

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

โ€Žjump-game/mike2ox.tsโ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Source: https://leetcode.com/problems/jump-game/
3+
* ํ’€์ด๋ฐฉ๋ฒ•: ๊ทธ๋ฆฌ๋””๋กœ ์ ‘๊ทผ
4+
*
5+
* ์‹œ๊ฐ„๋ณต์žก๋„: O(n) - nums์˜ ์š”์†Œ๋“ค์„ ๋‹ค ๋ฐฉ๋ฌธํ•  ์ˆ˜ ์žˆ์Œ
6+
* ๊ณต๊ฐ„๋ณต์žก๋„: O(1) - ํŠน์ • ์œ„์น˜๋งŒ ๊ธฐ์–ตํ•ด๋‘˜ ํ•„์š”๊ฐ€ ์žˆ์Œ
7+
*
8+
* ๋‹ค๋ฅธ ํ’€์ด
9+
* - DFS๋กœ ์ฒ˜์Œ์— ์ ‘๊ทผํ–ˆ์œผ๋‚˜ ์‹œ๊ฐ„ ์˜ค๋ฒ„๋กœ ์ธํ•ด Fail
10+
*/
11+
12+
function canJump(nums: number[]): boolean {
13+
let goal = nums.length - 1;
14+
for (let i = nums.length - 1; i >= 0; i--) {
15+
const pos = nums[i];
16+
if (pos + i >= goal) {
17+
goal = i;
18+
}
19+
}
20+
return goal === 0;
21+
}

0 commit comments

Comments
ย (0)