Decode Ways
Transitions
Top-down
def decode_ways(s):
def ways(i):
if i >= len(s): return 1
if s[i] == '0': return 0
ans = ways(i + 1)
if i + 1 < len(s) and (s[i] == '1' or (s[i] == '2' and s[i + 1] <= '6')):
ans += ways(i + 2)
return ans
return ways(0)Bottom-up

Last updated