Morse_tab = [".-","-...","-.-.",
"-..",".","..-.","--.","....",
"..",".---","-.-",".-..","--",
"-.","---",".--.","--.-",".-.",
"...","-","..-","...-",".--",
"-..-","-.--","--.."]
class Solution(object):
# https://leetcode.com/problems/unique-morse-code-words/solution/
def uniqueMorseRepresentations(self, words):
"""
:type words: List[str]
:rtype: int
"""
if len(words) == 0:
return 0
ans_set = set()
for word in words:
morsed = ""
for c in word:
morsed += Morse_tab[ord(c) - ord('a')]
ans_set.add(morsed)
return len(ans_set)
Download Unique Morse Code Words.pyLeetcode 804 Unique Morse Code Words problem solution in python3 with explanation. This is the best place to expand your knowledge and get prepared for your next interview.
Feedback is the most important part of any website.
If you have any query, suggestion or feedback, Please feel free to contact us.