728x90
https://leetcode.com/problems/decode-the-message
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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2006. Count Number of Pairs With Absolute Difference K (0) | 2024.02.22 |
---|---|
[Leetcode] 2367. Number of Arithmetic Triplets (0) | 2024.02.22 |
[Leetcode] 1630. Arithmetic Subarrays (0) | 2024.02.20 |
[Leetcode] 1656. Design an Ordered Stream (0) | 2024.02.19 |
[Leetcode] 535. Encode and Decode TinyURL (0) | 2024.02.18 |