今年我想陪着 30 天之 26

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

var uniqueMorseRepresentations = function(words) {
    code = [".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."];
    codeStore = [];
    for (let i = 0; i < words.length; i++){
        decode = "";
        word = words[i];
        for (let j = 0; j < word.length; j++){
            decode += code[(word[j].charCodeAt() - 97)];
        }
        if (codeStore.includes(decode) != true){
            codeStore.push(decode)
        }
    }
    
    return codeStore.length;
};

<<:  Day26 - HTML 与 CSS (8) - 背景图片

>>:  Day 26 -- 3 Steps 部署Sidekiq 背景任务在 Heroku

内部稽核

前言 去看中医的时侯,中医师会先望闻问切评估病徵。 身体没病的时侯,去医院也会做点常规或自费项目,做...

day 11 - log服务想说的话

log是什麽?为什麽要写log? 写了有什麽帮助? 写log就像是在帮服务表达它的各种心情, 一个r...

Day 2 Docker 基本概念

在正式使用 docker 之前,需要先知道以下三个元素:映像档 ( Image )、容器 ( Con...

22.unity读取文字文件并分行(TextAsset、Split)

1.准备好文字文件 2.撰写能导入文字文件的脚本 参考TextAsset、Split using S...

Day 1 [Python ML] 30天内容介绍

简介 之前在kaggle上面学习到了很多Python应用在Machine Learning的方法 对...