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
前言 去看中医的时侯,中医师会先望闻问切评估病徵。 身体没病的时侯,去医院也会做点常规或自费项目,做...
log是什麽?为什麽要写log? 写了有什麽帮助? 写log就像是在帮服务表达它的各种心情, 一个r...
在正式使用 docker 之前,需要先知道以下三个元素:映像档 ( Image )、容器 ( Con...
1.准备好文字文件 2.撰写能导入文字文件的脚本 参考TextAsset、Split using S...
简介 之前在kaggle上面学习到了很多Python应用在Machine Learning的方法 对...