218. Decode Ways

MediumStringString

A message of digits is encoded with 'A'->1 ... 'Z'->26. Given a digit string s, return the number of ways to decode it. A leading zero or an invalid two-digit group makes that path invalid.

Input: A quoted digit string s.

Output: Integer — number of decodings.

Examples

Example 1
Input: "12"
Output: 2
Explanation: 'AB' or 'L'.
Example 2
Input: "226"
Output: 3
Explanation: 'BZ','VF','BBF'.
Example 3
Input: "06"
Output: 0
Explanation: Leading zero invalid.

Constraints

Asked by

InfosysMicrosoftFlipkartMetaAdobeAmazon
Solve this problem in the editor →