leetcode - 804 - 唯一摩爾斯密碼詞
class Solution:
def uniqueMorseRepresentations(self, words):
"""
:type words: List[str]
:rtype: int
"""
dic = {"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":"--.."}
morse=''
morse_list = []
mor_list = []
diff_morse=0
for word in words:
word = word.lower()
for i in word:
morse += dic[i]
morse_list.append(morse)
morse = ''
for mor in morse_list:
if mor not in mor_list:
mor_list.append(mor)
diff_morse += 1
return diff_morse