728x90
https://leetcode.com/problems/unique-morse-code-words
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
'IT > 코딩테스트' 카테고리의 다른 글
[Leetcode] 2913. Subarrays Distinct Element Sum of Squares I (0) | 2024.02.24 |
---|---|
[Leetcode] 2956. Find Common Elements Between Two Arrays (0) | 2024.02.23 |
[Leetcode] 1684. Count the Number of Consistent Strings (0) | 2024.02.23 |
[Leetcode] 1832. Check if the Sentence Is Pangram (0) | 2024.02.22 |
[Leetcode] 2006. Count Number of Pairs With Absolute Difference K (0) | 2024.02.22 |