Decode Ways - aloalgo

Decode Ways

Medium

You are given a non-empty string s that contains only digits. Remember that a message containing letters from A-Z can be encoded into numbers using a simple mapping: A corresponds to 1, B to 2, and so on, all the way up to Z which corresponds to 26.

Your task is to determine the total number of distinct ways to decode the given digit string s back into letters.

You can assume that the input string s will always be non-empty and will only contain digits.

Example 1

Input
"1"
Output
1
Explanation:

There is only one way to decode '1', which corresponds to the letter 'A'.

Example 2

Input
"127"
Output
2
Explanation:

The string '127' can be decoded in two ways: 'ABG' (1 2 7) or 'LG' (12 7).

Example 3

Input
"0"
Output
0
Explanation:

The string '0' cannot be decoded into any letter, so there are 0 ways to decode it.

Loading...
Input
"1"
Output
1

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!