PIXELBANKv8.2.1
Menu

Decode Ways

A message containing letters A-Z can be encoded as numbers: 'A' -> "1", 'B' -> "2", ..., 'Z' -> "26".

Given a string s containing only digits, return the number of ways to decode it.

Example:

Input:
226
Output:
3
Reasoning:
  • The input string 226 can be decoded as follows:
    • 2 as 'B',
    • 2 as 'B',
    • 6 as 'F', resulting in one possible decoding: 'BBF'.
  • Another possible decoding is:
    • 22 as 'V',
    • 6 as 'F', resulting in 'VF'.
  • A third possible decoding is:
    • 2 as 'B',
    • 26 as 'Z', resulting in 'BZ'.
  • The total number of ways to decode 226 is the sum of these possibilities, which is 1+1+1=31 + 1 + 1 = 3.
  • The final output is 33.

Constraints:

  • 1 <= len(s) <= 100
  • s contains only digits
  • s does not contain leading zeros except "0" itself
Editor

Test Results

0/0
Run code to see test results.