[LeetCode&Python] Problem 804. 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 table for the 26 letters of the English alphabet is given below:
[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cab" can be written as "-.-.-....-", (which is the concatenation "-.-." + "-..." + ".-"). We'll call such a concatenation, the transformation of a word.
Return the number of different transformations among all words we have.
Example:
Input: words = ["gin", "zen", "gig", "msg"]
Output: 2
Explanation:
The transformation of each word is:
"gin" -> "--...-."
"zen" -> "--...-."
"gig" -> "--...--."
"msg" -> "--...--." There are 2 different transformations, "--...-." and "--...--.".
Note:
- The length of
words
will be at most100
. - Each
words[i]
will have length in range[1, 12]
. words[i]
will only consist of lowercase letters.
class Solution:
def uniqueMorseRepresentations(self, words):
"""
:type words: List[str]
:rtype: int
"""
sta=[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."] w=[] for s in words:
a=''
for c in s:
a=a+sta[ord(c)-ord('a')]
if not a in w:
w.append(a)
return len(w)
[LeetCode&Python] Problem 804. Unique Morse Code Words的更多相关文章
- 【Leetcode_easy】804. Unique Morse Code Words
problem 804. Unique Morse Code Words solution1: class Solution { public: int uniqueMorseRepresentati ...
- 804. Unique Morse Code Words - LeetCode
Question 804. Unique Morse Code Words [".-","-...","-.-.","-..&qu ...
- 【Leetcode】804. Unique Morse Code Words
Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...
- 【LeetCode】804. Unique Morse Code Words 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 set + map set + 字典 日期 题目地 ...
- [LeetCode] 804. Unique Morse Code Words 独特的摩斯码单词
International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...
- LeetCode 804 Unique Morse Code Words 解题报告
题目要求 International Morse Code defines a standard encoding where each letter is mapped to a series of ...
- LeetCode 804. Unique Morse Code Words (唯一摩尔斯密码词)
题目标签:String 题目给了我们 对应每一个 字母的 morse 密码,让我们从words 中 找出 有几个不同的 morse code 组合. 然后只要遍历 words,把每一个word 转换成 ...
- Leetcode 804. Unique Morse Code Words 莫尔斯电码重复问题
参考:https://blog.csdn.net/yuweiming70/article/details/79684433 题目描述: International Morse Code defines ...
- (string 数组) leetcode 804. Unique Morse Code Words
International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...
随机推荐
- STL__size_t, ptrdiff_t, size_type, difference_type
http://blog.csdn.net/zhaowei123191/article/details/5617559 ize_t 是unsigned类型, 用于指明数组长度或下标,它必须是一个正数,s ...
- Linux - 命令重定向
命令重定向, 就是将目前得到的数据转移到指定的地方.分为以下几种: >>>1>2>1>>2>>< 1. > 与 >>先看一 ...
- Shell循环输入符合条件为止
提供用户输入,直到输入d/D/r/R为止. #!/bin/bash ]; do echo -n "(D)ebug or (R)elease?" read select_build_ ...
- HDU 6090 Rikka with Graph
Rikka with Graph 思路: 官方题解: 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...
- Java注解的使用,类似于C#的Attribute
1.定义注解,代码如下: import java.lang.annotation.*; /** * 定义注解类,用于注解某个类或方法 * * @author Administrator * */ @T ...
- 流氓 2345.com的新动态及解决方法
安装了[电脑公司]的Win7_SP1之后, IE的主页被绑架. 症状是先转到 IE959.com,然后自动跳转到 www.2345.com 网上当然有很多例子了,可是都没有效果. 1. 更改IE设置没 ...
- 各个安卓版本 使用的 Linux Kernel Version
Android Version |API Level |Linux Kernel in AOSP --------------------------------------------------- ...
- 第5章——使用 Razor(MVC框架视图引擎)
Razor 是MVC框架视图引擎的名称. 本章提供 Razor 语法的快速教程,以使你能够识别 Razor 表达式. 本章不打算提供 Razor 的完整参考,而将其视为一个语法速成教程.在本书的后续内 ...
- OAF日志使用总结
本文的完成感谢葛严大神授权使用LogUtil类,其次感谢Tavor大神的EBS OAF开发日志(见: EBS OAF开发中日志(Logging) ). 日志的使用是一门极大的学问,若读者有兴趣,可以自 ...
- OAF中多语言的实现(转)
正好前两天研究过这个问题,分享一下啊. 标题: OAF中多语言的实现概述: OAF的多语言的实现有两种方式,其一是直接通过页面上面的“个性化”连接,连接到指定的页面后,进行 ...