International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-""b" maps to "-...""c"maps to "-.-.", and so on.

For convenience, the full table for the 26 letters of the English alphabet is given below:

[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]

Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, "cba" can be written as "-.-..--...", (which is the concatenation "-.-." + "-..." + ".-"). We'll call such a concatenation, the transformation of a word.

Return the number of different transformations among all words we have.

Example:
Input: words = ["gin", "zen", "gig", "msg"]
Output: 2
Explanation:
The transformation of each word is:
"gin" -> "--...-."
"zen" -> "--...-."
"gig" -> "--...--."
"msg" -> "--...--." There are 2 different transformations, "--...-." and "--...--.". 加班之余水个题~ 利用一下set的唯一性,效率还挺高
class Solution {
public int uniqueMorseRepresentations(String[] words) {
if (words == null)
return 0;
String[] codes = new String[]{".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."};
int len = words.length;
Set<String> set = new HashSet<>();
for (int i=0; i<len; i++) {
String word = words[i];
StringBuilder codeBuilder = new StringBuilder();
for (int j=0; j<word.length(); j++) {
codeBuilder.append(codes[word.charAt(j)-'a']);
}
set.add(codeBuilder.toString());
}
return set.size();
}
}

LeetCode - 804. Unique Morse Code Words的更多相关文章

  1. LeetCode 804. Unique Morse Code Words (唯一摩尔斯密码词)

    题目标签:String 题目给了我们 对应每一个 字母的 morse 密码,让我们从words 中 找出 有几个不同的 morse code 组合. 然后只要遍历 words,把每一个word 转换成 ...

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

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

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

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

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

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

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

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

  6. [LeetCode] 804. Unique Morse Code Words_Easy tag: Hash Table

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

  7. 804. Unique Morse Code Words - LeetCode

    Question 804. Unique Morse Code Words [".-","-...","-.-.","-..&qu ...

  8. 【Leetcode_easy】804. Unique Morse Code Words

    problem 804. Unique Morse Code Words solution1: class Solution { public: int uniqueMorseRepresentati ...

  9. 【Leetcode】804. Unique Morse Code Words

    Unique Morse Code Words Description International Morse Code defines a standard encoding where each ...

随机推荐

  1. IO流(2)—知识结构

    结构: 注:此IO包下主要介绍: 节点流:(字节流)FileInputStream.FileOutputStream.(字符流)Filereader.FileWriter 处理流(缓冲流):(字节流) ...

  2. HTML5 学习03——内联 SVG

    什么是SVG? SVG 指可伸缩矢量图形 (Scalable Vector Graphics) SVG 用于定义用于网络的基于矢量的图形 SVG 使用 XML 格式定义图形 SVG 图像在放大或改变尺 ...

  3. SpringBoot无废话入门02:SpringBoot启动分析

    1.核心注解 在上文中,我们讲到了@SpringBootApplication是SpringBoot的核心注解. 可以很方便的在idea中下载源码来查看该注解的源码,如下: 可以看到,该注解本身又被其 ...

  4. rvs产生服从指定分布的随机数 pdf概率密度函数 cdf累计分布函数 ppf 分位点函数

    统计工作中几个常用用法在python统计函数库scipy.stats的使用范例. 正态分布以正态分布的常见需求为例了解scipy.stats的基本使用方法. 1.生成服从指定分布的随机数 norm.r ...

  5. kettle 6.1 按时间增量抽取数据

    1.设计一个增量 配置表ETL_INCREMENTAL,用于配置表的增量时间等数据 2.增量JOB全图如下: 2.1获取增量时间变量,并设置增量变量 2.2 表的增量转换,在表中引用2.1的增量变量 ...

  6. oracle去掉字段全部空格进行模糊查询

    sql如下: select * from pwlp_law_person where replace(name,' ','') like replace('吕 刚',' ','');

  7. MySQL表最大能达到多少?

    MySQL 3.22限制的表大小为4GB.由于在MySQL 3.23中使用了MyISAM存储引擎,最大表尺寸增加到了65536TB(2567– 1字节).由于允许的表尺寸更大,MySQL数据库的最大有 ...

  8. Android_Printservice_API_部分翻译

    文件夹 * package android.printservice * public abstract class PrintService * public abstract class Prin ...

  9. iOS实现图片裁剪功能,基于TKImageView完善与讲解

    1.功能需求:需要实现图片区域裁剪功能. 2.效果图:     3.实现原理:本来想自己实现的,刚好看到一个比较好的库:TKImageView,下载好研究了下,发现基本都能满足我的需求,而且封装的也比 ...

  10. [转]awsome-java

    原文链接 Awesome Java A curated list of awesome Java frameworks, libraries and software. Contents Projec ...