dsa · medium

Decode Ways

A message of letters A-Z is encoded as 1 → A, 2 → B, …, 26 → Z. Given a string s of digits, return how many ways it can be decoded. A leading zero cannot start a code ("06" is 0 ways).

Arguments

Example

"12"2 (AB = 1,2 or L = 12).

"226"3 (BZ 2,26 / VF 22,6 / BBF 2,2,6).

"06"0.

Constraints

1 <= s.length <= 100 s contains only digits and may contain leading zeros Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
"12"

Expected:
2

Example 2

Input:
"226"

Expected:
3

Example 3

Input:
"06"

Expected:
0

Open in the Dojo editor