[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 ...
随机推荐
- Java注册帐号邮箱激活验证实现
Java注册帐号邮箱激活验证实现 1.需要加入发送邮件的mail.jar: http://www.oracle.com/technetwork/java/javamail/index-138643.h ...
- Netty优雅退出机制和原理
1.进程的优雅退出 1.1.Kill -9 PID带来的问题 在Linux上通常会通过kill -9 pid的方式强制将某个进程杀掉,这种方式简单高效,因此很多程序的停止脚本经常会选择使用kill - ...
- Mysql错误: Lock wait timeout exceeded 解决办法
一.临时解决办法: 执行mysql命令:show full processlist; 然后找出插入语句的系统id 执行mysql命令:kill id 或 首先,查看数据库的进程信息: show ful ...
- Python并行(parallel)之谈
简介 可以先看看并发Concurrent与并行Parallel的区别 在谈并行前,头脑中总会浮出多线程.多进程.线程/进程同步.线程/进程通信等词语. 那为什么需要同步.通信,它们之间的作用是怎样的呢 ...
- h1042 N!大数乘int
计算10000以内某个数的阶乘,即大数乘以int,考虑到一个int存一个数位过于繁琐且浪费空间,采用万进制 一个int存四个位数,但注意除了最高位,其他位不够四位数时要加上前导0凑够四位: 例1234 ...
- 决策树ID3算法实现
决策树的ID3算法基于信息增益来选择最优特征,于是自己实现了一把,直接上代码. """ CreateTime : 2019/3/3 22:19 Author : X Fi ...
- getTransaction().commit(),getDBTransaction().commit(),getOADBTransaction().commit之间的区别
原文: Transaction is an interface which provides base methods for defining database transactions.DBTra ...
- sort中的比较函数compare
sort中的比较函数compare要声明为静态成员函数或全局函数,不能作为普通成员函数,否则会报错: invalid use of non-static member function 因为:非静态成 ...
- Linux文件与目录管理(一)
一.Linux文件与目录管理 1.Linux的目录结构是树状结构,最顶级的目录是根目录/(用"/"表示) 2.Linux目录结构图: /bin:bin是Binary的缩写,这个目录 ...
- iOS UI-集合视图(UICollectionView)
BowenCollectionViewCell.xib #import <UIKit/UIKit.h> @interface BowenCollectionViewCell : UICol ...