804. Unique Morse Code Words
Last updated
Last updated
nternational 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.
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.
將 Morse Code 和 字母做成對應的 Dictionary
創立一個 SET 來儲存結果
以每個字為單位,轉成 Morse Code 後存進 SET 中
return set 的長度(所含相異值個數)
將題目中的 Morse Code 設定為一 List
創立一個 SET 來儲存結
將每個字母轉換成 ASCII 再減 97 即是 List 中相對應的位置
以每個字為單位,轉成 Morse Code 後存進 SET 中
return set 的長度(所含相異值個數)
welcome to check my Github LeetCode-share()