File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ *@link https://leetcode.com/problems/jump-game/description/
3
+ *
4
+ * μ κ·Ό λ°©λ² :
5
+ * - νμ¬ μΈλ±μ€μμ μ΅λλ‘ λλ¬ν μ μλ μΈλ±μ€λ₯Ό κ°±μ νμ¬ λ§μ§λ§ μΈλ±μ€μ λλ¬ν μ μλμ§ μ²΄ν¬
6
+ * - μ΅λ λλ¬ν μ μλ μΈλ±μ€κ° νμ¬ μΈλ±μ€λ³΄λ€ μμΌλ©΄, μ΄νλ νμΈν νμ μμΌλκΉ false 리ν΄
7
+ *
8
+ * μκ°λ³΅μ‘λ : O(n)
9
+ * - n = λ°°μ΄μ κΈΈμ΄, λ°°μ΄ 1νλ§ μν
10
+ *
11
+ * 곡κ°λ³΅μ‘λ : O(1)
12
+ * - κ³ μ λ λ³μλ§ μ¬μ©
13
+ */
14
+
15
+ function canJump ( nums : number [ ] ) : boolean {
16
+ const lastIndex = nums . length - 1 ;
17
+ let maxReachableIndex = 0 ;
18
+
19
+ for ( let i = 0 ; i < nums . length ; i ++ ) {
20
+ if ( maxReachableIndex < i ) return false ;
21
+
22
+ maxReachableIndex = Math . max ( maxReachableIndex , i + nums [ i ] ) ;
23
+
24
+ if ( lastIndex <= maxReachableIndex ) return true ;
25
+ }
26
+
27
+ return false ;
28
+ }
You canβt perform that action at this time.
0 commit comments