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 57995e0 commit 66f1107Copy full SHA for 66f1107
dynamic_programming/decode_ways.py
@@ -10,24 +10,23 @@
10
'''
11
12
def num_decodings(s: str):
13
- '''
+ """
14
>> num_decodings("12")
15
2
16
>> num_decodings("226")
17
3
18
19
if not s or int(s[0]) == 0:
20
return 0
21
22
last = 1
23
second_last = 1
24
-
+
25
for i in range(1, len(s)):
26
27
# 0 is a special digit since it does not
28
# correspond to any alphabet but can be
29
# meaningful if preceeded by 1 or 2
30
31
if s[i] == "0":
32
if s[i-1] in {"1", "2"}:
33
curr = second_last
@@ -47,4 +46,4 @@ def num_decodings(s: str):
47
46
if __name__ == "__main__":
48
import doctest
49
50
- doctest.testmod()
+ doctest.testmod()
0 commit comments