Class Solution
java.lang.Object
g0801_0900.s0804_unique_morse_code_words.Solution
804 - Unique Morse Code Words.<p>Easy</p>
<p>International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows:</p>
<ul>
<li><code>'a'</code> maps to <code>".-"</code>,</li>
<li><code>'b'</code> maps to <code>"-..."</code>,</li>
<li><code>'c'</code> maps to <code>"-.-."</code>, and so on.</li>
</ul>
<p>For convenience, the full table for the <code>26</code> letters of the English alphabet is given below:</p>
<p>[“.-”,“-…”,“-.-.”,“-..”,“.”,“..-.”,“–.”,“….”,“..”,“.—”,“-.-”,“.-..”,“–”,“-.”,“—”,“.–.”,“–.-”,“.-.”,“…”,“-”,“..-”,“…-”,“.–”,“-..-”,“-.–”,“–..”]</p>
<p>Given an array of strings <code>words</code> where each word can be written as a concatenation of the Morse code of each letter.</p>
<ul>
<li>For example, <code>"cab"</code> can be written as <code>"-.-..--..."</code>, which is the concatenation of <code>"-.-."</code>, <code>".-"</code>, and <code>"-..."</code>. We will call such a concatenation the <strong>transformation</strong> of a word.</li>
</ul>
<p>Return <em>the number of different <strong>transformations</strong> among all words we have</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> words = [“gin”,“zen”,“gig”,“msg”]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The transformation of each word is:</p>
<p>“gin” -> “–…-.”</p>
<p>“zen” -> “–…-.”</p>
<p>“gig” -> “–…–.”</p>
<p>“msg” -> “–…–.”</p>
<p>There are 2 different transformations: “–…-.” and “–…–.”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> words = [“a”]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= words.length <= 100</code></li>
<li><code>1 <= words[i].length <= 12</code></li>
<li><code>words[i]</code> consists of lowercase English letters.</li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
uniqueMorseRepresentations
-