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, "cba" 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 "--...--.". 加班之余水个题~ 利用一下set的唯一性,效率还挺高
class Solution {
public int uniqueMorseRepresentations(String[] words) {
if (words == null)
return 0;
String[] codes = new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
int len = words.length;
Set<String> set = new HashSet<>();
for (int i=0; i<len; i++) {
String word = words[i];
StringBuilder codeBuilder = new StringBuilder();
for (int j=0; j<word.length(); j++) {
codeBuilder.append(codes[word.charAt(j)-'a']);
}
set.add(codeBuilder.toString());
}
return set.size();
}
}

LeetCode - 804. Unique Morse Code Words的更多相关文章

  1. LeetCode 804. Unique Morse Code Words (唯一摩尔斯密码词)

    题目标签:String 题目给了我们 对应每一个 字母的 morse 密码,让我们从words 中 找出 有几个不同的 morse code 组合. 然后只要遍历 words,把每一个word 转换成 ...

  2. [LeetCode] 804. Unique Morse Code Words 独特的摩斯码单词

    International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...

  3. Leetcode 804. Unique Morse Code Words 莫尔斯电码重复问题

    参考:https://blog.csdn.net/yuweiming70/article/details/79684433 题目描述: International Morse Code defines ...

  4. (string 数组) leetcode 804. Unique Morse Code Words

    International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...

  5. LeetCode 804 Unique Morse Code Words 解题报告

    题目要求 International Morse Code defines a standard encoding where each letter is mapped to a series of ...

  6. [LeetCode] 804. Unique Morse Code Words_Easy tag: Hash Table

    International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...

  7. 804. Unique Morse Code Words - LeetCode

    Question 804. Unique Morse Code Words [".-","-...","-.-.","-..&qu ...

  8. 【Leetcode_easy】804. Unique Morse Code Words

    problem 804. Unique Morse Code Words solution1: class Solution { public: int uniqueMorseRepresentati ...

  9. 【Leetcode】804. Unique Morse Code Words

    Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...

随机推荐

  1. RAID各种级别详细介绍

    独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(RAID, Redundant Array of Inexpensive ...

  2. pygame 笔记-10 摩擦力与屏幕环绕

    多年前写过一篇 Flash/Flex学习笔记(25):摩擦力与屏幕环绕,可惜的当时上传的flash,服务器后来无人维护,现在flash链接都失效了.本篇用pygame重新实现了一个: 原理是类似,但要 ...

  3. 【独家】硅谷创业公司在中国常跌的五个坑|禾赛科技CEO李一帆柏林亚太周主题演讲

    [独家]硅谷创业公司在中国常跌的五个坑|禾赛科技CEO李一帆柏林亚太周主题演讲 李一帆 Xtecher特稿作者 关注  Xtecher推荐   演讲者:李一帆   翻译:晓娜   网址:www.xt ...

  4. Nginx反向代理400错误

    错误:使用Nginx的反向代理访问tomcat时400错误. upstream配置: upstream java_test{ server 127.0.0.1:8080; } 原因:nginx中ups ...

  5. 开源MSSQL Express Profile 文件

    https://files.cnblogs.com/files/mqingqing123/ExpressProfile.rar

  6. iOS:基于RTMP的视频推流

    iOS基于RTMP的视频推流 一.基本介绍 iOS直播一出世,立马火热的不行,各种直播平台如雨后春笋,正因为如此,也同样带动了直播的技术快速发展,在IT界精通直播技术的猴子可是很值钱的.直播技术涉及的 ...

  7. 超好用的Vim配置

    https://github.com/ma6174/vim-deprecated 简易安装方法: 打开终端,执行下面的命令就自动安装好了: wget -qO- https://raw.github.c ...

  8. 安装配置Xdebug模块详解

    1.XDebug安装配置 (1)下载XDebug下载地址:http://www.xdebug.org/必须下载跟机器上安装的php匹配的版本才行.具体下载方法如下:将phpinfo网页的源代码拷贝到h ...

  9. MyBatis(四):mybatis中使用in查询时的注意事项

    准备工作 1)创建测试表jobitem CREATE TABLE "jobitem" ( "id" ) NOT NULL AUTO_INCREMENT COMM ...

  10. javascript 生成MD5加密

    进行HTTP网络通信的时候,调用API向服务器请求数据,有时为了防止API调用过程中被黑客恶意篡改,所请求参数需要进行MD5算法计算,得到摘要签名.服务端会根据请求参数,对签名进行验证,签名不合法的请 ...