We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 84fe468 commit 6ac686fCopy full SHA for 6ac686f
โdecode-ways/jungsiroo.py
@@ -0,0 +1,26 @@
1
+class Solution:
2
+ def numDecodings(self, s: str) -> int:
3
+ """
4
+ dp ์ด์ฉ : ๊ฐ๋ฅํ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ตฌํด๋๊ณ ๊ทธ ๋ค์ ๋ถ์ ์ ์๋๊ฐ?
5
+ ex) 1234
6
+ (1,2) -> (1,2,3)
7
+ (12) -> (12,3)
8
+ (1) -> (1,23)
9
+
10
+ Tc : O(n) / Sc : O(n)
11
12
+ if s[0] == '0': return 0
13
14
+ n = len(s)
15
+ dp = [0]*(n+1)
16
+ dp[0] = dp[1] = 1
17
18
+ for i in range(2, n+1):
19
+ one = int(s[i-1])
20
+ two = int(s[i-2:i])
21
22
+ if 1<=one<=9: dp[i] += dp[i-1]
23
+ if 10<=two<=26 : dp[i] += dp[i-2]
24
25
+ return dp[n]
26
0 commit comments