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 ...
随机推荐
- java设计模式之策略模式总结
策略模式的定义:(定义截自http://www.cnblogs.com/whgk/p/6087064.html) 1.策略模式定义了算法族,分别封装起来,让他们之间可以互相替换,此模式让算法的变化独立 ...
- HDU_1561_The more, The Better_树型dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1561 The more, The Better Time Limit: 6000/2000 MS (J ...
- day16-常用模块I(time、datetime、random、os、sys、json、pickle)
目录 time模块 datetime模块 random模块 os模块 sys模块 json模块与pickle模块 json pickle time模块 time模块一般用于不同时间格式的转换,在使用前 ...
- JDBC配置MSSQL
使用JDBC连接SQL SERVER 这可能是个很老套的话题,但不管怎么说还是有用的.姑且把配置方法贴出来吧.1. 确认Sql Server的的运行状态打开Sql Server配置管理器,确认Sql ...
- Java基本输入输出
Java基本输入输出 基本输入 基本输出 package com.ahabest.demo; public class Test { public static void main(String[] ...
- cmd命令安装、卸载、启动和停止Windows Service
1.运行--〉cmd:打开cmd命令框 2.在命令行里定位到InstallUtil.exe所在的位置 InstallUtil.exe 默认的安装位置是在C:/Windows/Microsoft.NET ...
- CF 429B B.Working out (四角dp)
题意: 两个人一个从左上角一个从左下角分别开始走分别走向右下角和右上角,(矩阵每个格子有数)问到达终点后可以得到的最大数是多少,并且条件是他们两个相遇的时候那个点的数不能算 思路: 首先这道题如果暴力 ...
- 迷宫自动生成以及基于DFS的自动寻路算法
直接贴代码 #include<ctime> #include<conio.h> #include<iostream> #include<windows.h&g ...
- Linux:DHCP服务配置
DHCP服务程序能够使局域网内的主机自动且动态的获取IP地址.子网掩码.网关地址以及DNS服务器地址等信息. 说明:先安装DHCP服务 yum install dhcp -y ...
- FJoi2017 1月21日模拟赛 comparison(平衡树+thita重构)
题目大意: 经黄学长指出,此题原题出自2014湖北省队互测 没有人的算术 规定集合由二元组(A,B)构成,A.B同时也是两个这样的集合,即A.B本身也是二元组 规定二元组S为严格最小集合,S=(S,S ...