专栏首页SnailTyanLeetcode 804. Unique Morse Code Words

Leetcode 804. Unique Morse Code Words

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

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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • leetcode-804-Unique Morse Code Words

    chenjx85
  • LeetCode 804 Unique Morse Code Words

    首先为每个单词的每个字符进行转码, 将转码后的数据放到 Set 集合中, 最后返回 Set 的长度。

    一份执着✘
  • LeetCode 804. Unique Morse Code Words

    International Morse Code defines a standard encoding where each letter is mapped...

    Angel_Kitty
  • Leetcode-Easy 804. Unique Morse Code Words

    804. Unique Morse Code Words 描述: 将26个因为字母映射为莫尔斯式电码 ? 思路: 一一匹配 代码 clas...

    致Great
  • LeetCode - 唯一摩尔斯密码词

    LeetCode第804题,难度简单。莫尔斯码,记是记不住的,但是理解还是能够理解的。

    晓痴
  • 2.leetcode唯一的摩斯密码

    1.题目 International Morse Code defines a standard encoding where each letter is m...

    py3study
  • LeetCode 804. 唯一摩尔斯密码词(哈希+set)

    国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: “a” 对应 “.-”, “b” 对应 “-…”, “c” 对应...

    Michael阿明
  • 力扣(LeetCode)刷题,简单题(第18期)

    力扣(LeetCode)定期刷题,每期10道题,业务繁重的同志可以看看我分享的思路,不是最高效解决方案,只求互相提升。

    不脱发的程序猿
  • Leetcode 139 Word Break

    Given a string s and a dictionary of words dict, determine if s can be segmente...

    triplebee

扫码关注云+社区

领取腾讯云代金券