文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
az = [chr(x) for x in range(ord('a'), ord('z') + 1)]
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
mapping = {}
for i in range(len(morse)):
mapping[az[i]] = morse[i]
result = set()
for word in words:
temp = ''
for ch in word:
temp = temp + mapping[ch]
result.add(temp)
return len(result)