1
class Solution:
2
def uniqueMorseRepresentations(self, words: List[str]) -> int:
3

4
# create a dictionary for morse code (You can just copy & paste it! ^.^)
5
ENG_to_MORSE = {
6
"a": ".-",
7
"b": "-...",
8
"c": "-.-.",
9
"d": "-..",
10
"e": ".",
11
"f": "..-.",
12
"g": "--.",
13
"h": "....",
14
"i": "..",
15
"j": ".---",
16
"k": "-.-",
17
"l": ".-..",
18
"m": "--",
19
"n": "-.",
20
"o": "---",
21
"p": ".--.",
22
"q": "--.-",
23
"r": ".-.",
24
"s": "...",
25
"t": "-",
26
"u": "..-",
27
"v": "...-",
28
"w": ".--",
29
"x": "-..-",
30
"y": "-.--",
31
"z": "--..",
32
}
33

34
cnt = {} # dictionary for different transformations
35

36
for word in words: # loop through every word
37

38
tmp = ""
39

40
for c in word: # loop through every character
41
tmp += ENG_to_MORSE[c] # convert the word to morse code
42

43
if tmp not in cnt:
44
cnt[tmp] = 0
45
else:
46
cnt[tmp] += 1
47

48
return len(cnt) # return how many different elements in cnt

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0