LeetCode:804. Unique Morse Code Words

高斯-约当(Gauss-Jordan)消元法——c++代码实现 具体算法的详细原理请参照此篇博客:高斯-约当(Gauss-Jordan)消元法下面是具体c++代码,不保证程序最优化,提供一个可行的程序,供大家改进,同时感谢大家提意见。——大神勿喷呀,我是一个小菜鸟~void Guss_Jordan(int n,double *a)//阶数n 系数矩阵a { double*a_temp = new double[n*n * 2];//a与单位矩阵的组合 阅读详情

链接:
https://leetcode.com/problems/unique-morse-code-words/description/

题目:
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, “cab” 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 “–…–.”.

Note:

The length of words will be at most 100.
Each words[i] will have length in range [1, 12].
words[i] will only consist of lowercase letters.

思路:
set运用,ord简化解题
这里写图片描述

class Solution:
    def __init__(self):
        self.table = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
                 "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
        self.alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
                 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
    def uniqueMorseRepresentations(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        morse_code_set = set()
        for word in words:
            morse_code = ''
            for alpha in word:
                idx = self.alpha.index(alpha)
                morse_code += self.table[idx]
            morse_code_set.add(morse_code)
        return len(morse_code_set)

或者

class Solution:
    def __init__(self):
        self.table = [".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", "--",
                 "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", "-.--", "--.."]
    def uniqueMorseRepresentations(self, words):
        """
        :type words: List[str]
        :rtype: int
        """
        morse_code_set = set()
        for word in words:
            morse_code = ''
            for alpha in word:
                morse_code += self.table[ord(alpha) - ord('a')]
            morse_code_set.add(morse_code)
        return len(morse_code_set)
绿米Aqara S1【妙控开关 S1E】版本降级或升级自定义固件的方法 阅读详情

相关推荐

2021电子科技大学分布式系统期末考点精析与实战解析

本文深入解析2021年电子科技大学分布式系统期末考试核心考点,包括分布式事务、时钟同步、GFS架构等高频内容。基于回忆版试题,提供实战解析与应试技巧,帮助考生高效复习。重点涵盖两阶段提交、Cristian算法等关键技术,适合计算机专业学生备考参考。

weixin_29251131的博客 540

LeetCode | 804. Unique Morse Code Words

题外话:时间会在指尖悄悄流逝,转眼我也毕业了。整理好行囊,明天去公司报道。打开Leetcode才发现,原来题目都出到800+了。回想当初刚知道这个平台的时候,只有300+的题目,还想计算怎么刷完全部。如今看着这个数字,更是有些却步。不过,只有一直往前,可能才能有希望,如果一直停滞,了无生趣,这样才更加让自己失望。所以,不管是多么的不确定,不管还有多少的未知,不管会对发现自己还有多少没有学习的内容,...

iLOVEJohnny的博客 1983

Cadence——原理图相关教程

包含创建文件,原理图,元器件,规则检查,PDF与BOM清单输出,各类PCB网表

haonanyayaya的博客 1万+

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

题目描述: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 o

yuweiming70的博客 2314

【MNE脑电信号处理学习笔记1】数据的读取、可视化、剪裁、滤波和保存

MNE之读取原始数据、可视化数据、剪裁数据、滤波和保存 Reading & visualizaing raw data, cropping, filtering, and saving 原视频教程:Pybrain: M/EEG analysis with MNE Python 原笔记和材料:pybrain_mne 本文根据视频和个人理解对原笔记进行细微修改。 Import the few packages we’ll need import matplotlib import pathlib i

小白家 4214

unity转微信小游戏:UI大小设置

unity转微信小游戏:UI大小设置

会潜水的小火龙的博客 3270

804. Unique Morse Code Words

804. Unique Morse Code Words 题目: 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...

学渣阿衰的家 245

Avellaneda & Stoikov’s market-making strategy 工程化处理

前2篇文章详细介绍了AS存货模型的做市策略,这次对于这些公式里面一些希腊字母的取值是如何计算的,如何做工程化并应用到生产环境中做一些说明。这个里面有一些重要参数:很直观,可以直接取值的有:s = current market mid price (中间价,也就是【最佳卖价+最佳买价】/2)q = quantity of assets in inventory of base asset (也就是买入多少价值的股票数量)

weixin_42480337的博客 7068

Leetcode 804: Unique Morse Code Words

问题描述: 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

weixin_51401145的博客 99

UE4_SpeedTree Shader源码分析

目录 1.UMaterialExpressionSpeedTree::Compile 2.Compiler->SpeedTree 3.GetSpeedTreeVertexOffset 4.Scene中的SpeedTree应用 (Scene->UpdateSpeedTreeWind) 5.GetSpeedTreeVertexOffsetInner 由于之后做风场,也需要在S...

zzgyy123的专栏 2631

【FISCO BCOS】二十、多机部署区块链

实际开发中,为了满足高可用性和高容错性的需求,往往会采用多级部署区块链的方式,今天介绍一下FISCO BCOS的多机部署流程。

naihe_fish的博客 3651

[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 and dashes, as follows:"a"maps to".-","b"maps to"-...","c"maps to"-.-.", and so on. For co...

weixin_30586085的博客 89

产品路线图的三种模型(RICE/MoSCoW/Kano),教你如何对需求进行优先级排序

RICE/MoSCoW/Kano三种模型,教你如何对需求进行优先级排序。 也许你会让业务提供一份ROI,记得前不久参加过一场立项会评审,一位很有意思的小产品在会上讲不清楚ROI,评审们要求会后重新梳理,小产品表达不要为难业务方干一些他们不擅长的事了。这个看似笑话的经历,背后隐藏着价值判断已经流于形式。 也许你会要求业务方直接给出需求优先级列表,把任务分为P0到P5,这样的划分除了按需求本质的优先级还同时考虑了开发资源、开发难度等问题。毫不夸张地说,我曾经拿到一张全是P0级别的需求清单,如果一切任务都是高

wenyusuran的专栏 5540

数据结构与算法:leetcode_804_Unique Morse Code Words

Description 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 s...

技术总结之路~ 271

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

LeetCode:804. Unique Morse Code Words唯一摩尔斯密码词(C语言)

题目描述: 国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串, 比如: “a” 对应 “.-”, “b” 对应 “-…”, “c” 对应 “-.-.”, 等等。 为了方便,所有26个英文字母对应摩尔斯密码表如下: [".-","-…","-.-.","-…",".","…-.","–.","…","…",".—","-.-",".-…","–","-.","—",".–.","–.-",".-.","…","-","…-","…-",".–","-…-","-.–","–

C/C++攻城狮 298

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

LeetCode //C - 804. Unique Morse Code Words

Summary: The problem requires counting the number of unique Morse code transformations for a given list of words. Each letter is converted to its Morse code equivalent, and the transformations are formed by concatenating these codes. A hash set is used to

Made in Code 1354

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Leetcode刷题 804. Unique Morse Code Words

Leetcode 804.Unique Morse Code Words题目解题思路参考解法set容器排序去重总结set更优解 题目 【 英文 】:International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “...

ride_view的博客 234

LeetCode 804 Unique Morse Code Words

LeetCode 804 Unique Morse Code Words 传送门 题目分析 International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "...

博客 999

[LeetCode] 804. Unique Morse Code Words(map)

题目链接:804. Unique Morse Code Words 解题思路:没什么技巧,构造 map 作为密码字典,生成的摩斯密码插入到一个 unordered_set 中,因为元素具有唯一性,所以可以直接求个数。 class Solution { public: int uniqueMorseRepresentations(vector<string>& wo...

Selukwe的博客 341

LeetCode 804. Unique Morse Code Words

804. Unique Morse Code Words(唯一摩尔斯密码词) 题目:      国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串,比如:"a"对应".-","b"对应"-...","c"对应"-.-.", 等等。   为了方便,所有26个英文字母对应摩尔斯密码表如下:   [".-","-...","-.-.",...

weixin_30650039的博客 139

【Leetcode】804. Unique Morse Code Words

804. Unique Morse Code Wordshttps://leetcode.com/problems/unique-morse-code-words/description/International Morse Code defines a standard encoding where each letter is mapped to a series of dots and d...

1128

[LeetCode] 804. Unique Morse Code Words

Description 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 "-.-.",...

dfojc86648的专栏 105

Leetcode 804.Unique Morse Code Words (Java)

问题描述: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

lovrain的博客 777

[leetcode] 804. Unique Morse Code Words

Description 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 ...

Learning from the mistakes 148

804. Unique Morse Code Words*

804. Unique Morse Code Words* https://leetcode.com/problems/unique-morse-code-words/ 题目描述 International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashe...

珍妮的选择的博客 276
上一篇: LeetCode:626. Exchange Seats
下一篇: LeetCode:461. Hamming Distance
SCUTJcfeng
博客等级 码龄9年 57粉丝 43原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值