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 798ef63 commit d5e98d4Copy full SHA for d5e98d4
โjump-game/jdy8739.jsโ
@@ -0,0 +1,28 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {boolean}
4
+ */
5
+var canJump = function (nums) {
6
+ const dp = new Array(nums.length).fill(false);
7
+
8
+ dp[0] = true;
9
10
+ for (let i = 0; i < nums.length; i++) {
11
+ if (!dp[i]) {
12
+ continue;
13
+ }
14
15
+ for (let j = 1; j < nums[i] + 1; j++) {
16
+ if (i + j >= nums.length) {
17
+ break;
18
19
20
+ dp[i + j] = true;
21
22
23
24
+ return dp[dp.length - 1];
25
+};
26
27
+// ์๊ฐ๋ณต์ก๋ O(n2) -> nums์ ๊ธธ์ด๋๋ก ์ํํ๋ฉด์ 1๋ถํฐ nums[j]์ ๊ฐ๊น์ง ์ํํ๋ 2์ค ๋ฃจํ๋ฅผ ๋๊ธฐ ๋๋ฌธ
28
+// ๊ณต๊ฐ๋ณต์ก๋ 0(n) -> nums์ ๊ธธ์ด์ ๋ฐ๋ผ dp ๋ฐฐ์ด์ ๊ธธ์ด๊ฐ ๊ฒฐ์ ๋๋ฏ๋ก
0 commit comments