Decode Ways

A message containing letters fromA-Zis being encoded to numbers using the following mapping:

'A' -
>
 1
'B' -
>
 2
...
'Z' -
>
 26

Given anon-emptystring containing only digits, determine the total number of ways to decode it.

Example 1:

Input:
 "12"

Output:
 2

Explanation:
 It could be decoded as "AB" (1 2) or "L" (12).

Example 2:

二刷看注释

for 1:n

Last updated

Was this helpful?