#91

Decode Ways

expert · 1070 · lc medium +32 · 37.7% accepted · 12,833 likes · top 16%

play →

Description

A digit string encodes a message using the mapping 1→A, 2→B, …, 26→Z. Groups of digits form letters, but leading zeros are invalid (e.g., "06" is not a valid encoding). Given digit-only string s, return the total number of valid decodings, or 0 if none exist. The answer fits in a 32-bit integer.

Code

1
2
3