题目标签: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 2008 防火墙开放端口

    当我们使用新服务器架设新主机时,经常会遇到网站无法访问的情况,当问及客服时,经常会告知,操作系统默认不打开80端口,请先确定80是否打开并确定没有被占用.那么,我们该如何打开80端口呢? 方法/步骤 ...

  2. ubuntu系统nginx+Redis+PHP

    一.安装ngnix apt-get update sudo apt-get install nginx /etc/init.d/nginx start 二.安装php sudo apt-get ins ...

  3. HDU_1175_连连看

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1175 大意:连连看规则,只能转两次弯,先输入矩阵0表示没有棋子,正整数表示不同的棋子,然后询问,输入两点坐 ...

  4. RocketMQ学习笔记(16)----RocketMQ搭建双主双从(异步复制)集群

    1. 修改RocketMQ默认启动端口 由于只有两台机器,部署双主双从需要四个节点,所以只能修改rocketmq的默认启动端口,从官网下载rocketmq的source文件,解压后使用idea打开,全 ...

  5. tp系统常量

    ThinkPHP的公共入口文件里定义了系统常量 RUNTIME_PATH----系统运行时目录 LIB_PATH-----------系统核心类库目录 CORE_PATH--------Think类库 ...

  6. Python学习第二阶段Day2(json/pickle)、 shelve、xml、PyYAML、configparser、hashlib模块

    1.json/pickle   略. 2.shelve模块 import shelve # shelve 以key value的形式序列化,value为对象 class Foo(object): de ...

  7. MySQL Insert数据量过大导致报错 MySQL server has gone away

    接手了同事的项目,其中有一个功能是保存邮件模板(包含图片),同事之前的做法是把图片进行base64编码然后存在mysql数据库中(字段类型为mediumtext)然后保存三张图片(大概400k)的时候 ...

  8. Django DTL模板语法中的循环的笔记

    for...in...笔记: for...in...标签: for...in...类似于Python中的for...in....可以遍历列表.元组.字符串.字典等一切可以遍历的对象.示例代码如下: { ...

  9. 51nod1429 巧克力

    [题解] 找一下两个面积s1,s2的2和3的因子数,把他们除掉,如果s1,s2不相等,就是-1,否则可以用s1,s2的2和3的因子数计算答案. #include<cstdio> #incl ...

  10. [bzoj3209][花神的数论题] (数位dp+费马小定理)

    Description 背景众所周知,花神多年来凭借无边的神力狂虐各大 OJ.OI.CF.TC …… 当然也包括 CH 啦.描述话说花神这天又来讲课了.课后照例有超级难的神题啦…… 我等蒟蒻又遭殃了. ...