본문 바로가기

IT/코딩테스트

[Leetcode] 804. Unique Morse Code Words

728x90

https://leetcode.com/problems/unique-morse-code-words

 

Unique Morse Code Words - LeetCode

Can you solve this real interview question? Unique Morse Code Words - Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

class Solution:
    def uniqueMorseRepresentations(self, words: List[str]) -> int:
        morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]

        trans = []
        for word in words:
            word_trans = ""
            for n in word:
                word_trans += morse[ord(n) - 97]
            trans.append(word_trans)

        return len(list(set(trans)))
728x90