Skip to content

Commit eb8217b

Browse files
committed
feat: search-in-rotated-sorted-array solution
1 parent a8ec2b3 commit eb8217b

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

โ€Žjump-game/YeomChaeeun.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
ย (0)