-
w : current answer of decode ways
-
v : previous answer of decode ways
-
pre : previous character
Complexity T : O(n)
class Solution:
def numDecodings(self, s):
"""
:type s: str
:rtype: int
"""
v, w, pre = 0, int(len(s) > 0), ''
for c in s:
v, w, pre = w, (c > '0') * w + (9 < int(pre + c) < 27) * v, c
return w