Leetcode Problem 2325. Decode the Message

2325. Decode the Message

Leetcode Solutions

Mapping Cipher Key to Alphabet

  1. Initialize an empty dictionary char_map to store the mapping from the cipher key to the alphabet.
  2. Initialize a variable current_char to 'a' to keep track of the current alphabet character to map to.
  3. Iterate through each character in the key string.
    • If the character is not a space and not already in char_map, add it to char_map with the value of current_char.
    • Increment current_char to the next letter in the alphabet.
  4. Initialize an empty string decoded_message to build the decoded message.
  5. Iterate through each character in the message string.
    • If the character is a space, add a space to decoded_message.
    • Otherwise, add the corresponding character from char_map to decoded_message.
  6. Return decoded_message as the final decoded message.
UML Thumbnail

Character Index Mapping

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...