Skip to content

Latest commit

 

History

History
24 lines (22 loc) · 733 Bytes

804.md

File metadata and controls

24 lines (22 loc) · 733 Bytes

804. Unique Morse Code Words

Solution 1 (time O(n), space O(n))

class Solution(object):
    def uniqueMorseRepresentations(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        d = dict(zip("abcdefghijklmnopqrstuvwxyz",
                     [".-","-...","-.-.","-..",".","..-.","--.",
                      "....","..",".---","-.-",".-..","--","-.",
                      "---",".--.","--.-",".-.","...","-",
                      "..-","...-",".--","-..-","-.--","--.."]))
        seen = set([])
        for word in words:
            t = ""
            for c in word:
                t += d[c]
            seen.add(t)
        return len(seen)