题目标签:String

  题目给了我们 对应每一个 字母的 morse 密码,让我们从words 中 找出 有几个不同的 morse code 组合。

  然后只要遍历 words,把每一个word 转换成 morse code,把 唯一的 存入 HashSet 就可以了,最后返回 set 的 size。

Java Solution:

Runtime beats  99.77%

完成日期:07/02/2018

关键词:HashSet

关键点:把唯一morse code 存入 set

 class Solution
{
public int uniqueMorseRepresentations(String[] words)
{
String[] mcLetters = {".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."}; Set<String> result = new HashSet<>(); for(String word: words)
{
char[] arr = word.toCharArray();
String mc = ""; for(char c: arr)
{
mc += mcLetters[c - 'a'];
} result.add(mc);
} return result.size();
}
}

参考资料:n/a

LeetCode 题目列表 - LeetCode Questions List

题目来源:https://leetcode.com/

LeetCode 804. Unique Morse Code Words (唯一摩尔斯密码词)的更多相关文章

  1. Leetcode804.Unique Morse Code Words唯一摩尔斯密码词

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

  2. Java实现 LeetCode 804 唯一摩尔斯密码词 (暴力)

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

  3. [Swift]LeetCode804. 唯一摩尔斯密码词 | Unique Morse Code Words

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

  4. 力扣(LeetCode)804. 唯一摩尔斯密码词

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

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

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

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

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

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

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

  8. LeetCode - 804. Unique Morse Code Words

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

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

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

随机推荐

  1. Windows离线安装Python第三方库的方法

    在window中,离线安装第三方模块, 1.下载第三方库的压缩文件,解压,将解压后的文件放到Python安装目录下的Lib\site_packages中 2. 将Python添加到环境变量里 3.进入 ...

  2. ES6字符串模板

    这里做个简单的拓展,之前做vue组件时,经常用到拼接字符串,换行时用到\,既费时又麻烦.这里介绍个ES6字符串模板方法 旧版拼接(各种换行拼接) Vue.component('obj-prop',{ ...

  3. linux 挂载数据盘

    完整的阿里云挂载数据盘方法如下: 1.入手阿里云后查看有几块硬盘:(只显示概况,不显示分区情况) fdisk -l|grep Disk 2.查看硬盘分区 fdisk -l 如果有提示:disk /de ...

  4. 【转载】Appium环境搭建(Windows版)

    注:appium安装到C盘,node.js安装到C盘 一.安装node.js 1.到官网下载node.js:https://nodejs.org/en/download/ 2.获取到安装文件后,直接双 ...

  5. Luogu P4016 「 网络流 24 题 」负载平衡问题

    吐槽题目难度,这个题建模好像比前两个都要难,但是难度评级却比第二个要低. 解题思路 依旧是考虑如何建模和建立源点汇点.每个点的货物数量到最后都一样的话肯定是等于他们的平均值.用 $num$ 数组存储原 ...

  6. 每日命令:(10)cat

    cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1.命令格式: cat [选项] [文件] ...

  7. linux下Mongodb集群搭建:分片+副本集

    三台服务器 192.168.1.40/41/42 安装包 mongodb-linux-x86_64-amazon2-4.0.1.tgz 服务规划  服务器40  服务器41  服务器42  mongo ...

  8. 爬虫实战(三) 用Python爬取拉勾网

    目录 0.前言 1.初始化 2.爬取数据 3.保存数据 4.数据可视化 5.大功告成 0.前言 最近,博主面临着选方向的困难(唉,选择困难症患者 >﹏<),所以希望了解一下目前不同岗位的就 ...

  9. 【Python实践-9】将字符串转化为浮点型

    利用map和reduce编写一个str2float函数,把字符串'123.456'转换成浮点数123.456. 思路:计算小数位数--->将字符串中的小数点去掉--->字符串转换为整数-- ...

  10. 2.5.5.2 特殊文件:/dev/null 与 /dev/tty

        UNIX 系统提供了两个对Shell编程特别有用的特殊文件.       第一个文件 /dev/null ,就是大家所熟知的位桶(bit bucket).传送到此文件的数据都会被丢掉.换句话说 ...