File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * μΈμ½λ λ λ©μΈμ§λ₯Ό λμ½λ(decode)νλ €λ©΄, λ§΅νμ κ·μΉμ λ°λλ‘ μ μ©νμ¬ μ«μλ₯Ό λ€μ μνλ²³ λλ¬Έμλ‘ λλ €λμΌ νλ€.
3+ * μλ₯Ό λ€μ΄, μ«μ 11106μ 1 1 10 6μΌλ‘ λΆν νλ©΄ AAJFλ‘ λμ½λν μλ μκ³ , 11 10 6μΌλ‘ λΆν νλ©΄ KJFλ‘λ λμ½λν
4+ μ μλ€.
5+ * λ¬Έμμ΄ νμ
μ μ«μκ° μ£Όμ΄μ‘μ λ μνλ²³ λ¬Έμμ΄λ‘ λμ½λν μ μλ λ°©λ²μ κ°μλ₯Ό ꡬνλΌ.
6+ * @param {string } s
7+ * @return {number }
8+ */
9+ var numDecodings = function ( s ) {
10+ const memo = new Map ( ) ;
11+ memo . set ( s . length , 1 ) ;
12+
13+ function dfs ( start ) {
14+ if ( memo . has ( start ) ) {
15+ return memo . get ( start ) ;
16+ }
17+
18+ // 0μΌλ‘ μμνλ©΄ ν΄μ λΆκ°
19+ if ( s [ start ] === "0" ) {
20+ memo . set ( start , 0 ) ;
21+ return 0 ;
22+ }
23+
24+ let count = dfs ( start + 1 ) ; // ν κΈμ ν΄μ
25+
26+ // λ κΈμ ν΄μ κ°λ₯ν κ²½μ°
27+ if ( start + 1 < s . length && parseInt ( s . substring ( start , start + 2 ) ) <= 26 ) {
28+ count += dfs ( start + 2 ) ;
29+ }
30+
31+ memo . set ( start , count ) ;
32+ return count ;
33+ }
34+
35+ return dfs ( 0 ) ;
36+ } ;
You canβt perform that action at this time.
0 commit comments