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 a8ec2b3 commit eb8217bCopy full SHA for eb8217b
โjump-game/YeomChaeeun.ts
@@ -0,0 +1,27 @@
1
+/**
2
+ * ์ ํ ๊ฒ์ ํ์ฌ ์ธ๋ฑ์ค์์ ์ธ๋ฑ์ค ๊ฐ๋งํผ ์ ํํ์ฌ ๋ง์ง๋ง ์ธ๋ฑ์ค๊น์ง ๋๋ฌํ ์ ์๋์ง ๊ตฌํ๊ธฐ
3
+ * ์๊ณ ๋ฆฌ์ฆ ๋ณต์ก๋
4
+ * - ์๊ฐ ๋ณต์ก๋: O(n2)
5
+ * - ๊ณต๊ฐ ๋ณต์ก๋: O(n)
6
+ * @param nums
7
+ */
8
+function canJump(nums: number[]): boolean {
9
+ const dp = new Array(nums.length).fill(false)
10
+
11
+ dp[0] = true
12
+ for(let i = 0; i < nums.length; i++) {
13
+ if(!dp[i]) continue;
14
15
+ for(let step = 1; step <= nums[i]; step++) {
16
+ if(i + step < nums.length) {
17
+ dp[i + step] = true;
18
+ }
19
20
21
+ if(dp[nums.length -1]) {
22
+ return true;
23
24
25
26
+ return dp[nums.length - 1];
27
+}
0 commit comments