804. Unique Morse Code Words - LeetCode
Question

[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]
Solution
题目大意:
根据对应的编码规则将字符串数组中每个字符串编码,这样就得到一个编码后的数组,数组去重后返回数组大小
思路:用set来保存编码后的字符串
Java实现:
public int uniqueMorseRepresentations(String[] words) {
String[] arr = {".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."};
Set<String> codeSet = new HashSet<>();
for (String word : words) {
String code = "";
for (char c : word.toCharArray()) {
code += arr[c - 'a'];
}
/*if (!codeSet.contains(code)) {
codeSet.add(code);
}*/
codeSet.add(code);
}
return codeSet.size();
}
804. Unique Morse Code Words - LeetCode的更多相关文章
- 【Leetcode_easy】804. Unique Morse Code Words
problem 804. Unique Morse Code Words solution1: class Solution { public: int uniqueMorseRepresentati ...
- 【Leetcode】804. Unique Morse Code Words
Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...
- LeetCode 804. Unique Morse Code Words (唯一摩尔斯密码词)
题目标签:String 题目给了我们 对应每一个 字母的 morse 密码,让我们从words 中 找出 有几个不同的 morse code 组合. 然后只要遍历 words,把每一个word 转换成 ...
- [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 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 set + map set + 字典 日期 题目地 ...
- 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 ...
随机推荐
- Cloud Design Patterns & Architecture Styles
Cloud Design Patterns Categories Data Management Design and Implementation Messaging Patterns Ambass ...
- 所有用CSS3写的3D特效,都离不开这些知识
起因 昨晚在做慕课网的十天精通CSS3课程,其中的综合练习是要做一个3D导航翻转的效果.非常高大上. 以往这些效果我都很不屑,觉得网上一大堆这些特效的代码,复制粘贴就好了,够快.但是现实工作中,其实自 ...
- 体验js之美第八课-面向对象创建和继承终结篇
概述 到这里我们讲说js面向对象的系列部分的最后一个课程,面向对象必须掌握两个东西一个是对象的创建一个是继承.这节课我们重点说说这两个问题最后我们说下在ES6里面面向对象怎么玩. 1对象的创建 我们第 ...
- ES6-11学习笔记--数组遍历
ES5中数组遍历方式: for循环 forEach():没有返回值,只是针对每个元素调用func map():返回新的Array,每个元素为调用func的结果 filter():返回符合func条件的 ...
- Java/C++实现命令模式---多次撤销和撤回
某系统需要提供一个命令集合(注:可以使用链表,栈等集合对象实现),用于存储一系列命令对象,并通过该命令集合实现多次undo()和redo()操作,可以使用加法运算来模拟实现.\ 类图: Java代码: ...
- Spring核心 IoC和AOP原理
1. 什么是Spring Spring是一个轻量的Java开源框架,它简化了应用开发,实现基于POJO的编程模型.它的两大核心是:IoC(控制反转),AOP(面向切面编程). 2. IoC控制反转 简 ...
- 解决帝国CMS搜索页面模板不支持灵动标签和万能标签的方法
1,打开 /e/search/result/index.php 文件 查找 require("../../class/connect.php"); require(".. ...
- golang-grpc
目录 1. 什么是grpc和protobuf 1.1 grpc 1.2 protobuf 2.go下grpc 2.1官网下载protobuf工具 2.2 下载go的依赖包 2.3 编写proto文件 ...
- 渗透测试中为什么https抓包是明文传输?
网站用的是https抓包是明文传输,为什么能看到https报文的明文? https其实就是 http + SSL/TLS 两种协议的合体.http协议是应用层协议,而SSL/TLS是传输层协议. 那问 ...
- Net程序崩溃了怎么去查找定位问题
工具 这里用到两个工具分别为Procdump+Windbg Procdump:ProcDump是一个命令行实用工具,主要目的是监视应用程序,以便在管理员或开发人员可用于确定峰值的原因期间监视 CPU ...