파비의 매일매일 공부기록

Today's Challenge 본문

Problem Solving/LeetCode

Today's Challenge

fabichoi 2022. 8. 17. 23:45

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

 

Unique Morse Code Words - LeetCode

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

오늘도 Easy 난이도긴 한데.. 뭔가 어려워.......보였는데 생각보다 쉬웠음

class Solution:
    def uniqueMorseRepresentations(self, words: List[str]) -> int:
        codes = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
        res = set()
        for word in words:
            trans_word = ''
            for w in word:                
                trans_word += codes[ord(w)-ord('a')]
            res.add(trans_word)
        return len(res)
반응형

'Problem Solving > LeetCode' 카테고리의 다른 글

Today's Challenge  (0) 2022.08.19
Today's Challenge  (0) 2022.08.18
Today's Challenge  (0) 2022.08.16
Today's Challenge  (0) 2022.08.15
Today's Challenge  (0) 2022.08.14
Comments