1、题目描述

2、题目分析

将words 中的每一个string  直接翻译成对应的Morse 码,然后将其放入 set 中,最后返回set的大小即可,此处利用的set 中元素不重复的性质。

3.代码

  1. vector<string> Morse = {".-","-...","-.-.","-..",".","..-.","--.","....","..",
  2. ".---","-.-",".-..","--","-.","---",".--.","--.-",".-.",
  3. "...","-","..-","...-",".--","-..-","-.--","--.."};
  4. std::set<std::string> myset;
  5.  
  6. for( auto &s: words)
  7. {
  8. string morse_s;
  9. for( auto it = s.begin() ; it !=s.end() ; ++it)
  10. {
  11. morse_s += Morse[ *it - 'a' ];
  12. }
  13. myset.insert( morse_s );
  14. }
  15. return myset.size();
  16.  
  17. }

LeetCode题解之Unique Morse Code Words的更多相关文章

  1. 【Leetcode】804. Unique Morse Code Words

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

  2. 【LeetCode】804. Unique Morse Code Words 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述: 题目大意 解题方法 set + map set + 字典 日期 题目地 ...

  3. LeetCode算法题-Unique Morse Code Words(Java实现)

    这是悦乐书的第318次更新,第339篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第186题(顺位题号是804).国际莫尔斯电码定义了一种标准编码,其中每个字母映射到一系 ...

  4. 804. Unique Morse Code Words - LeetCode

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

  5. Unique Morse Code Words

    Algorithm [leetcode]Unique Morse Code Words https://leetcode.com/problems/unique-morse-code-words/ 1 ...

  6. 【Leetcode_easy】804. Unique Morse Code Words

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

  7. [LeetCode] 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 (唯一摩尔斯密码词)

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

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

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

随机推荐

  1. sublime text ubuntu

    { "color_scheme": "Packages/User/SublimeLinter/Dawn (SL).tmTheme", "font_fa ...

  2. HTML编码规范 - 1

    用两个空格来代替制表符(tab) -- 这是唯一能保证在所有环境下获得一致展现的方法. 嵌套元素应当缩进一次(即两个空格). 对于属性的定义,确保全部使用双引号,绝不要使用单引号. 不要在自闭和(se ...

  3. CentOS6.5下Ambari安装搭建部署大数据集群(图文分五大步详解)(博主强烈推荐)

    第一步: Ambari安装之Ambari安装前准备(CentOS6.5)(一) 第二步: Ambari安装之部署本地库(镜像服务器)(二) 第三步: Ambari安装之安装并配置Ambari-serv ...

  4. Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解

    不多说,直接上干货! Ubuntukylin-14.04-desktop(带分区)安装步骤详解 Ubuntu14.04安装之后的一些配置 Ubuntukylin-14.04-desktop( 不带分区 ...

  5. nginx pcre错误

    以上错误是因为pcre的路径指定的不对,--with-pcre模块应该指向的是pcre解压后的源码包,而不是pcre的安装路径. ]$./configure --prefix=/data01/logs ...

  6. 图形学 shader教程推荐

    https://www.bilibili.com/video/av37119580  http://edu.manew.com/my/course/96 http://edu.manew.com/my ...

  7. 机器学习--聚类系列--DBSCAN算法

    DBSCAN算法 基本概念:(Density-Based Spatial Clustering of Applications with Noise) 核心对象:若某个点的密度达到算法设定的阈值则其为 ...

  8. springboot-14-自定义properties文件值注入javaBean中

    被这个问题困扰了好几天.... 在spring中, 从资源文件向bean中注入值非常简单, 只需要properties文件被spring加载, 然后在被spring管理的类写响应的属性, 然后 @Va ...

  9. Linux进程间通信 -- 管道(pipe)

    前言    进程是一个独立的资源管理单元,不同进程间的资源是独立的,不能在一个进程中访问另一个进程的用户空间和内存空间.但是,进程不是孤立的,不同进程之间需要信息的交互和状态的传递,因此需要进程间数据 ...

  10. 【angular5项目积累总结】文件下载

    download() { const token = localStorage.getItem('token'); let headers: HttpHeaders = new HttpHeaders ...