LeetCode804.唯一摩尔斯密码词

class Solution:
    def uniqueMorseRepresentations(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        table = [".-", "-...", "-.-.", "-..", ".",
         "..-.", "--.", "....", "..", ".---",
         "-.-", ".-..", "--", "-.", "---",
         ".--.", "--.-", ".-.", "...", "-",
         "..-", "...-", ".--", "-..-", "-.--", "--.."]
        dict={}
        dict = dict.fromkeys(words)
        for word in words:
            ch = ''
            for s in word:
                ch += table[ord(s) - 97]
            dict[word] = ch
        values = set(dict.values())
        return len(values)

posted @ 2018-05-04 09:21  kkkkkksssss  阅读(119)  评论(0编辑  收藏  举报