Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 91 Decode Ways - Problem Statement

LeetCode 91

A message of letters A-Z is represented as numbers: A=1A=1, B=2B=2, ..., Z=26Z=26. Given a string of digits like "226226", count how many ways you can decode it. "226226" can be "BZ" (22,2626), "VF" (2222,66), or "BBF" (22,22,66).

That's 33 ways. Before reading on, think: at each position, what choices do you have? And when is a choice invalid? Constraints: n100n \le 100. Watch for leading zeros: '06' is not a valid encoding.