2019年3月1日 804. Unique Morse Code Words

依旧不是难题,练手练手,这道题本来准备一次AC的,结果出现了两个笔误+一次读题错误,失败,还需要努力。

class Solution(object):
    def uniqueMorseRepresentations(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        latter = [".-","-...","-.-.","-..",".","..-.",
                  "--.","....","..",".---","-.-",".-..",
                  "--","-.","---",".--.","--.-",".-.",
                  "...","-","..-","...-",".--","-..-",
                  "-.--","--.."]
        
        result = set()        
        for w in words:
            s = ''
            for i in w:
                s += latter[ord(i) - ord('a')]
            
            result.add(s,)

                    
        return len(result)
posted @ 2019-03-01 09:37  miuc  阅读(71)  评论(0编辑  收藏  举报