Decode Ways

Given a string s containing only digits, return the number of ways to decode it where 'A' -> 1, 'B' -> 2, ..., 'Z' -> 26. Pattern focus: Decode ways. Each position depends on whether the previous one or two digits form a valid letter.

Input Format

s = digit string

Output Format

number of valid decodings

Constraints

  • 1 <= s.length <= 100; s contains only digits

Examples

Example 1:

Input:

s = "12"

Output:

2

Explanation:

12 can be decoded as AB or L.

Example 2:

Input:

s = "226"

Output:

3

Explanation:

The valid decodings are BZ, VF, and BBF.

Loading...
Decode Ways - Dp 1d DSA Problem