Decode Ways

Medium

A message of digits maps to letters with A = 1 … Z = 26. Given the digit string s, return the number of ways it can be decoded.

Example 1

numDecodings()
Input
s = "12"
Output
2

Why

"AB" (1 2) or "L" (12)

Example 2

numDecodings()
Input
s = "226"
Output
3
Constraints
1 <= s.length <= 100
`s` contains digits only and may contain leading zeros.

Topics

Dynamic ProgrammingStrings

Implement numDecodings in the editor and return the answer — printing it is never graded.