Leetcode 804. Unique Morse Code Words
Posted SnailTyan
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Leetcode 804. Unique Morse Code Words相关的知识,希望对你有一定的参考价值。
文章作者:Tyan
博客:noahsnail.com | CSDN | 简书
1. Description
2. Solution
- Version 1
class Solution:
def uniqueMorseRepresentations(self, words: List[str]) -> int:
az = [chr(x) for x in range(ord('a'), ord('z') + 1)]
morse = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
mapping = {}
for i in range(len(morse)):
mapping[az[i]] = morse[i]
result = set()
for word in words:
temp = ''
for ch in word:
temp = temp + mapping[ch]
result.add(temp)
return len(result)
Reference
以上是关于Leetcode 804. Unique Morse Code Words的主要内容,如果未能解决你的问题,请参考以下文章
leetcode-804-Unique Morse Code Words
LeetCode 804 Unique Morse Code Words 解题报告
Leetcode 804. Unique Morse Code Words
[LeetCode] 804. Unique Morse Code Words 独特的摩斯码单词