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+ * @param {number } n
3+ * @return {number }
4+ */
5+ var climbStairs = function ( n ) {
6+ // νΌλ³΄λμΉ μμ΄μ νμ©ν΄μ μ λ΅μ νμ΄μΌν κΉ?
7+ // νΌλ³΄λμΉ μμ΄μ΄λ: F(n) = F(n - 1) + F(n - 2);
8+ // λ°ν 쑰건μ nμ΄ 1λλ 0μΌ λ ν΄λΉ μλ₯Ό λ°νν μ μμ
9+ // μ΄ λ¬Έμ μμλ 2 κ³λ¨ μ€λ₯΄λ μν©μ ν¬ν¨μμΌμΌν΄μ n μ΄ 2μΌ λ 2λ₯Ό λ°ννλλ‘ μ€μ
10+ // κ·Όλ° μ΄μ μκ°μ΄κ³Όκ° λ°μν΄μ μΊμ± ν΄μ€μΌν¨.
11+ var cache = { '0' : 0 , '1' : 1 , '2' : 2 } ;
12+
13+ var fibo = ( n ) => {
14+ let result = 0 ;
15+
16+ if ( typeof ( cache [ n ] ) === 'number' ) {
17+ result = cache [ n ] ;
18+ } else {
19+ result = cache [ n ] = fibo ( n - 1 ) + fibo ( n - 2 ) ;
20+ }
21+
22+ return result ;
23+ } ;
24+
25+ return fibo ( n ) ;
26+ } ;
You canβt perform that action at this time.
0 commit comments