본문 바로가기

IT/코딩테스트

[Leetcode] 2325. Decode the Message

728x90

https://leetcode.com/problems/decode-the-message

 

LeetCode - The World's Leading Online Programming Learning Platform

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution:
    def decodeMessage(self, key: str, message: str) -> str:
        key = key.replace(' ', '')
        table = {}
        
        index = 0
        for n in key:
            if n == ' ':
                continue
            if table.get(n, None) is None:
                table[n] = chr(97 + index)
                index += 1

        result = ''
        for i in message:
            if i == ' ':
                result += i
            else:
                result += table[i]

        return result
728x90