leetcode 804. Unique Morse Code Words(独特的摩斯码单词)

桌面云虚拟机Ubuntu离线安装open-vm-tools 公司办公在桌面云中进行开发,桌面云是无法访问外网的,然后又有安装虚拟机的需求,使用VMware自带的VMware-tools安装功能失败,报错也需要联网才能解决,如果不安装VMware-tools,则虚拟机无法使用共享文件夹功能以及与本机共享剪贴板功能,非常难受,故自己研究解决如何离线安装open-vm-tools(open-vm-tools 是 VMware Tools 的开源实施)打开Ubuntu,可以在文件中看到生成的ISO文件,点开,将四个软件包复制粘贴至桌面。 阅读详情

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:

[“.-”,“-…”,“-.-.”,“-…”,“.”,“…-.”,“–.”,“…”,“…”,“.—”,“-.-”,“.-…”,“–”,“-.”,“—”,“.–.”,“–.-”,“.-.”,“…”,“-”,“…-”,“…-”,“.–”,“-…-”,“-.–”,“–…”]
Given an array of strings words where 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 of “-.-.”, “.-”, and “-…”. We will call such a concatenation the transformation of a word.
Return the number of different transformations among all words we have.

Example 1:

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 “–…–.”.

每个字母对应一个摩斯码,单词的摩斯码是字母摩斯码的拼接。
字符串数组words的单词中,有多少个不同的摩斯码。

思路:

就是简单地把每个单词的摩斯码都拼出来,然后看有几个不同的。
可用HashSet保存单词的摩斯码,重复的也只会保存一个,最后看hashSet的size即可。

拼摩斯码时可以直接用string的拼接,即string1 + string2的形式,
但是注意了,这个耗内存会比StringBuilder要大(但是也能通过测试),
因为String是不可变的对象,每次对String进行操作的时候,都会生成一个新的对象,这会对系统的性能造成影响。
而StringBuilder是对本身进行操作的。

public int uniqueMorseRepresentations(String[] words) {
    HashSet<String> set = new HashSet<>();
    
    String[] codes = new String[]{
       ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---",
        "-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-",
        "..-","...-",".--","-..-","-.--","--.."
    };
    
    for(String word : words) {
        StringBuilder code = new StringBuilder();
        for(int i = 0; i < word.length(); i++) {
            int idx = word.charAt(i) - 'a';
            code.append(codes[idx]);
        }
        set.add(code.toString());
    }
    
    return set.size();
}
转录因子详细介绍(motif) 转录因子详细介绍(motif) TF: transcription factor转录因子TFBS: transcription factor binding site转录因子结合位点TFBS是序列内的location,TF特异结合在这里,这个site有这种特点 1 和一些参考相关的一个位置(开始,结束,strand),这些reference可以是染色体开始,geneTSS。也可以是一段sequence 2 A SITE可以是实验证实的(已知的),也可以是一些算法(预测的) 3 例子,下面这个图是酵母 阅读详情

相关推荐

ROS激光雷达动态避障算法优化(C++实战)

本文深入探讨了ROS激光雷达动态避障算法的C++实战优化。针对动态环境的核心挑战,文章系统性地介绍了从激光数据预处理(降噪、瘦身)、动态障碍物检测与跟踪,到基于动态窗口法(DWA)的智能决策与调优的全流程。重点分享了如何将障碍物速度预测融入DWA打分函数,以实现更安全、流畅的避障,并提供了工程架构、性能优化及真机调试的实用建议。

weixin_29192141的博客 956

[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 co...

weixin_30699741的博客 132

多个MOS管并联应用场景的四大要点

动态运行时,阈值电压Vgsth最低的MOS管首先打开,最后关闭。这种MOS管一般会占据更多的开关损耗,并且在开关转换过程中,承担了更高的电应力。

VBsemi的博客 3767

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 1357

华为L420X/L540X信创笔记本从麒麟系统安装Windows ARM版实操指南

在计算机系统生态中,指令集架构决定了软件运行的基础,其中ARM作为精简指令集(RISC)的代表,与x86的复杂指令集(CISC)存在根本差异,因此操作系统与驱动的兼容性成为软硬件协同的关键。ARM架构处理器凭借低功耗与高能效比,在移动计算和桌面领域持续扩展,微软也为此提供了专用的Windows ARM版本。对于信创笔记本用户而言,当专业软件、考试环境或内部工具仅支持Windows平台时,在ARM设备上完成系统切换便具有明确的工程实践价值。本文以华为L420X/L540X搭载麒麟9000C芯片的信创笔记本为实

weixin_30444111的博客 831

ROS2理论与实践_宇树机器人Go2开发指南(文字)

本文介绍了Unitree Go2机器人ROS2开发环境的安装与配置流程。主要内容包括:1)从GitHub克隆unitree_ros2仓库;2)安装ROS2 Foxy版本依赖项;3)编译特定版本的CycloneDDS(0.10.2);4)编译unitree_go和unitree_api功能包;5)网络配置,包括设置静态IP和修改环境变量脚本setup.sh以指定网络接口。文章还提供了本地回环测试的替代方案,并建议配置完成后重启电脑。整个流程涉及ROS2环境切换、网络适配和编译安装等多个技术环节。

Li_Dongyi的博客 4232

LeetCode 804. Unique Morse Code Words

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

weixin_30650039的博客 140

VS Code/TRAE集成Cppcheck并启用MISRA规则

本文探讨了嵌入式开发中Cppcheck工具集成与MISRA规则检查的必要性。详细介绍了安装配置步骤:安装VSCode/TRAE、Cppcheck软件、配置插件参数、安装Python环境,并重点说明了MISRA规则文件的设置方法。通过完整的配置流程,实现了嵌入式开发环境下静态检查与安全标准的落地。

SDFangFang2025的博客 1293

leetcode 804. Unique Morse Code Words(python)

描述 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 Eng

王大呀呀的博客 293

从零到一:基于Blazor和Elsa Workflows的工作流系统开发实战

本文详细介绍了如何利用Blazor和Elsa Workflows构建高效的工作流系统,从技术选型到生产环境部署,涵盖动态工作流建模、Blazor前端集成及性能优化等核心内容。通过实战案例,展示如何实现订单处理系统的自动化与灵活性,提升企业流程效率。

weixin_26875109的博客 436

SAP_SD模块 物料科目分配/成本简介

路径:SPRO—销售与分销—基本功能—科目分配/成本—收入账户确定—收入科目确定相关性—定义并分配科目代码—定义科目代码。路径:SPRO—销售与分销—基本功能—科目分配/成本—收入账户确定—收入科目确定相关性—定义访问顺序和科目确定类型。路径:SPRO—销售与分销—基本功能—科目分配/成本—收入账户确定—收入科目确定相关性—定义并分配科目确定过程。文本主要说明销售模块中的科目分配和成本的一个对应关系。SPRO—销售与分销—基本功能—科目分配/成本—收入账户确定—检查科目分配的相关主数据。

我小时候很黑的博客 2625

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

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

Selukwe的博客 341

Spine骨骼动画查看器 - Skeleton Viewer

骨骼动画是现代游戏和动画制作中常用的技术之一。Spine骨骼动画查看器(Skeleton Viewer)是一个官方提供的工具,用于查看和调试Spine骨骼动画。本文将介绍Skeleton Viewer的功能和使用方法,并提供相应的源代码示例。通过Skeleton Viewer,开发者可以直观地查看和调试Spine骨骼动画,包括骨骼结构、动画播放和事件触发等。这有助于提高骨骼动画的质量和效果,并加速开发过程。以上代码演示了如何使用Skeleton Viewer查看和播放Spine骨骼动画。

HsvvDatabase的博客 3494

【Leetcode】804. Unique Morse Code Words

题目地址: https://leetcode.com/problems/unique-morse-code-words/ 给定一个字符串数组,代表每个字母对应的摩斯密码。再给定若干单词,求这些单词对应的摩斯密码的个数(需要去重)。 import java.util.HashSet; import java.util.Set; public class Solution { public int uniqueMorseRepresentations(String[] words) {

数学、算法爱好者的博客 158

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

LeetCode 804 Unique Morse Code Words--python,java解法

LeetCode 804 Unique Morse Code Words Difficulty:easy Acceptance:74.1% International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: “a” ...

个人博客 581

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

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

weixin_30492601的博客 128

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

【LeetCode】804. Unique Morse Code Words

题目:简述题目:    题目中给出了一个摩斯密码的对应数组,也就是每个字母分别对应的摩斯密码,然后给出一组单词,求最终不同的摩斯密码的个数(因为有些字母的摩斯密码的组合可能会相同)思路:    遍历,然后生成每个单词的莫斯密码,存储,求个数    我一开始用了hashmap,还统计了每个摩斯密码出现的个数,但是其实并么有这个必要,只需要知道一共有多少个不同的就行了,所以后来改用了hashset,可...

Mint_r的博客 314

Leetcode C++ 804. Unique Morse Code Words 【Set】

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

memcpy0的博客 566

Leetcode 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” ma...

u010065754的专栏 297

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

dey8091的博客 139

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

Weixu Liu的博客 208

LeetCode804. Unique Morse Code Words

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

Lightmare625 189

leetcode 804. Unique Morse Code Words(String、char、HashSet、ASC2)

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

DurianPudding的博客 236

Leetcode 804. Unique Morse Code Words python

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

weixin_40469199的博客 481

804. Unique Morse Code Words

804. Unique Morse Code Words 804. Unique Morse Code Words 题目 解决 题目 Leetcode题目 International Morse Code defines a standard encoding where each letter is mapped to a series of dots and das...

Valerie的博客 282

[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

魔豆(Magicbean)的博客 482
上一篇: leetcode 387. First Unique Character in a String(字符串中第一个独一无二的字母)
下一篇: cuda11安装 nvidia-455配置报错 解决方法
蓝羽飞鸟
博客等级 码龄8年 1万+粉丝 727原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝羽飞鸟

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址