You are given a non-empty string s that contains only digits. Remember that a message containing letters from A-Z can be encoded into numbers using a simple mapping: A corresponds to 1, B to 2, and so on, all the way up to Z which corresponds to 26.
Your task is to determine the total number of distinct ways to decode the given digit string s back into letters.
You can assume that the input string s will always be non-empty and will only contain digits.
"1"
1
There is only one way to decode '1', which corresponds to the letter 'A'.
"127"
2
The string '127' can be decoded in two ways: 'ABG' (1 2 7) or 'LG' (12 7).
"0"
0
The string '0' cannot be decoded into any letter, so there are 0 ways to decode it.
"1"
1