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