-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path804.py
20 lines (18 loc) · 890 Bytes
/
804.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Unique Morse Code Words
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
transformations = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
letters = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
a_dict = {}
for i in range(len(letters)):
a_dict[letters[i]] = transformations[i]
converted = []
transformations = 0
for word in words:
mapped = ""
for char in word:
mapped += a_dict[char]
if mapped not in converted:
converted.append(mapped)
transformations += 1
return transformations