LeetCode 804. Unique Morse Code Words (唯一摩尔斯密码词)
题目标签: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 (唯一摩尔斯密码词)的更多相关文章
- Leetcode804.Unique Morse Code Words唯一摩尔斯密码词
国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: "a" 对应 ".-", "b" 对应 &q ...
- Java实现 LeetCode 804 唯一摩尔斯密码词 (暴力)
804. 唯一摩尔斯密码词 国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: "a" 对应 ".-", " ...
- [Swift]LeetCode804. 唯一摩尔斯密码词 | Unique Morse Code Words
International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...
- 力扣(LeetCode)804. 唯一摩尔斯密码词
国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: "a" 对应 ".-", "b" 对应 &q ...
- 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 ...
- [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 dots ...
- LeetCode 804 Unique Morse Code Words 解题报告
题目要求 International Morse Code defines a standard encoding where each letter is mapped to a series of ...
随机推荐
- UVM基础之-------uvm report机制的使用
后面的例子我会继续补充: 1. 因为uvm默认定义的message格式比较长,非常不利于debug过程中的分析使用,一般情况下,开始使用uvm,都要利用uvm_report_server重新定义mes ...
- java 物理分页和逻辑分页
A.逻辑分页利用游标分页,好处是所有数据库都统一,坏处就是效率低.1.逻辑分页的第一种方式,利用ResultSet的滚动分页.这种分页方式依靠的是对结果集的算法来分页,因此通常被称为“逻辑分页”.步骤 ...
- android studio使用中碰到Failure [INSTALL_FAILED_OLDER_SDK] 问题
第一次使用Android studio开发.直接新建一个默认项目运行出现:Failure [INSTALL_FAILED_OLDER_SDK] , 网上很多人说修改build.gradle中的mins ...
- Android Studio 入门 Hello World
Android Studio 入门 Hello World Gavin要加油 1.5k 6月22日 发布 推荐 1 推荐 收藏 17 收藏,2.1k 浏览 引言 前两天开始学习android开发,本来 ...
- canvas一周一练 -- canvas绘制太极图(6)
运行效果: <!DOCTYPE html> <html> <head> </head> <body> <canvas id=" ...
- 运用反射时报错java.lang.NoSuchMethodException,以解决,记录一下
问题:想调用service类中的私有方法时, Method target=clz.getMethod("say", String.class);用Class的getMethod报错 ...
- (转)Hibernate框架基础——映射主键属性
http://blog.csdn.net/yerenyuan_pku/article/details/52740744 本文我们学习映射文件中的主键属性,废话不多说,直接开干. 我们首先在cn.itc ...
- Codeforces_776_C_(思维)(前缀和)
C. Molly's Chemicals time limit per test 2.5 seconds memory limit per test 512 megabytes input stand ...
- HDU_1242_Rescue
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1242 大意:迷宫搜索,'#'代表墙,'.'代表路,'x'代表守卫,每移动1格用1秒,杀死守卫用1秒,ang ...
- Android Measure 体系简单总结
Android对View的测量是半协商半强制半模糊半具体的. 测量过程中的两套尺寸体系: [半强制] ParentView**约束ChildView: **MeasureSpec(通过measure ...