804. Unique Morse Code Words
https://leetcode.com/problems/unique-morse-code-words/
Python
- Mapped them and remove duplicate with
set
from string import ascii_lowercase
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
mapper = {
letter: morse for letter, morse in zip(
ascii_lowercase,
[
".-","-...","-.-.","-..",".",
"..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",
".--.","--.-",".-.","...","-",
"..-","...-",".--","-..-","-.--",
"--.."
]
)
}
morses = set([''.join([mapper[letter] for letter in word]) for word in words])
return len(morses)