LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 2ms, memory 17.3MB, accepted 2026-01-01.

python
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)

Source