PIXELBANKv9.1.0
Menu

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 and may contain leading zeros
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.