Problem · String
Decode Numeric String
Learn this problemProblem statement
A message is encoded by mapping letters to numbers: A -> 1, B -> 2, ..., Z -> 26.
Given a numeric string digits, return the number of different ways it can be decoded into letters.
A one-digit code is valid when it is between 1 and 9. A two-digit code is valid when it is between 10 and 26.
Function
countDecodings(digits: String) → intExamples
Example 1
digits = "2116"return = 5The valid decodings split the string as 2,1,1,6, 21,1,6, 2,11,6, 2,1,16, and 21,16.
Constraints
1 <= digits.length <= 10^5digitsconsists of numeric characters.- The number of valid decodings is guaranteed to fit in a signed 32-bit integer.