Skip to content

Commit 0424c1b

Browse files
committed
feat(soobing): week10 > jump-game
1 parent 60843c3 commit 0424c1b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

β€Žjump-game/soobing.tsβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* 문제 ν•΄μ„€
3+
* - ν˜„μž¬ μœ„μΉ˜μ—μ„œ μ΅œλŒ€ 점프할 수 μžˆλŠ” 갯수λ₯Ό λ‹΄κ³  μžˆλŠ” λ°°μ—΄, λ§ˆμ§€λ§‰ ν•­λͺ©μ— 도달이 κ°€λŠ₯ν•œμ§€ λ°˜ν™˜ν•˜λŠ” 문제
4+
*
5+
* 아이디어
6+
* 1) 그리디 μ•Œκ³ λ¦¬μ¦˜
7+
* - 배열을 μ­‰ μˆœνšŒν•˜λ©΄μ„œ λ‹€μŒ 이동 κ°€λŠ₯ν•œ 횟수λ₯Ό λΉ„κ΅ν•˜μ—¬ λ‹€μŒ ν•­λͺ©μœΌλ‘œ 이동이 κ°€λŠ₯ν•œμ§€ 체크, μ—†λ‹€λ©΄ false λ°˜ν™˜.
8+
* - 일단 ν˜„μž¬κΉŒμ§€ μ™”λ‹€λ©΄ 이후에 μ΅œλŒ€λ‘œ 갈 수 μžˆλŠ” 값을 μ—…λ°μ΄νŠΈ.
9+
*/
10+
function canJump(nums: number[]): boolean {
11+
let reachable = 0;
12+
for (let i = 0; i < nums.length; i++) {
13+
if (i > reachable) return false;
14+
reachable = Math.max(reachable, i + nums[i]);
15+
}
16+
return true;
17+
}

0 commit comments

Comments
Β (0)