We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 04e55ea commit 1744c14Copy full SHA for 1744c14
โjump-game/mike2ox.tsโ
@@ -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