- See Code
O(nk)
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
vocab = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
res = set()
for w in words:
str = ''.join([vocab[ord(i) - 97] for i in w])
if str not in res:
res.add(str)
return len(res)