-
89. Unique Morse Code WordsProblem Solving 2023. 1. 19. 00:33728x90
https://leetcode.com/problems/unique-morse-code-words/description/
Unique Morse Code Words - LeetCode
Unique Morse Code Words - International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: * 'a' maps to ".-", * 'b' maps to "-...", * 'c' maps to "-.-.", and so on. For convenience, the full tabl
leetcode.com
리스트로 입력받은 단어들을 모스부호로 변환한 후, 중복 제거
class Solution: def uniqueMorseRepresentations(self, words: List[str]) -> int: alpha = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'] morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] encode = dict(zip(alpha, morse)) out = [] for i in words: word = "" for j in i: word = word + encode[j] if word not in out: out.append(word) return len(out)
'Problem Solving' 카테고리의 다른 글
91. Two Sum II - Input Array Is Sorted (0) 2023.01.19 90. Valid Parentheses (0) 2023.01.19 88. 욱제는 효도쟁이야!! (0) 2023.01.19 87. 등장하지 않는 문자의 합 (0) 2023.01.18 86. 쉽게 푸는 문제 (0) 2023.01.18