Loading...
Loading...
Loading...
A message uses the codes 1 to 26 for letters, 1 for A up to 26 for Z. A string of digits can be split into codes in several ways. Print the number of ways to read the whole string. Print 0 if it cannot be read.
Example 1
Input
226
Output
3
The readings are 2-2-6, 22-6 and 2-26.
Example 2
Input
06
Output
0
Try the problem first. Open one hint at a time.
A cell adds the cell before it if the last digit is not 0, and the cell two before if the last two digits are 10 to 26.
Start with dp[0] = 1 and dp[1] = 1, and return 0 if the string starts with 0.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor