2406. Decode the Message
My accepted Python solution to LeetCode problem 2406, Decode the Message, running in 2ms.
- Difficulty: Easy
- Python
- Runtime 2ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 2ms, memory 17.3MB, accepted 2026-01-01.
class Solution:
def decodeMessage(self, key: str, message: str) -> str:
mapping = {}
idx = 0
for c in key:
if c != ' ' and c not in mapping:
mapping[c] = chr(ord('a') + idx)
idx += 1
return ''.join(mapping.get(c, c) for c in message)