Decode Ways
Analysis
We should utilize the dynamic perogramming, the transfer equation is, suppose result[i] is the number of decoding ways ending at s[i]
result[i] = result[i-1] + result[i-2] (If both s[i-1~ i] and s[i] is valid)
result[i] = result[i-1] (If only s[i] is valid)
Pay attention to the corner case!!!!
Solution
1 | class Solution: |