Given the mapping a = 1, b = 2, ... z = 26, and an encoded message message (as a string), count the number of ways it can be decoded.
For example, the message 111
should return 3
, since it could be decoded as aaa
, ka
, and ak
.
You can assume that the messages are decodable.
For example, 001
is not a valid input.
Input
message = "111"
Output
3
Explanation
This can be decoded 3 ways: aaa, ak, and ka.
Input
message = "8"
Output
1
Explanation
This can be only decoded one way, as h.
Input
message = "12"
Output
2
Explanation
This can be decoded 2 ways: ab or l.