class Solution:
    def uniqueMorseRepresentations(self, words: List[str]) -> int:
        """ tc O(N*W*M)  W: len of word, N number of words, M: len of morse code 
        
        """
        res = set()
        d = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
        for w in words:
            tmp = '' # optimize:can use arr to cache first and join in one round 
            for c in w:
                tmp += d[ord(c)-ord('a')]
            res.add(tmp)
        return len(res)