java.lang.Object
g0801_0900.s0804_unique_morse_code_words.Solution

public class Solution extends Object
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>&quot;.-&quot;</code>,</li> <li><code>'b'</code> maps to <code>&quot;-...&quot;</code>,</li> <li><code>'c'</code> maps to <code>&quot;-.-.&quot;</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>[&ldquo;.-&rdquo;,&ldquo;-&hellip;&rdquo;,&ldquo;-.-.&rdquo;,&ldquo;-..&rdquo;,&ldquo;.&rdquo;,&ldquo;..-.&rdquo;,&ldquo;&ndash;.&rdquo;,&ldquo;&hellip;.&rdquo;,&ldquo;..&rdquo;,&ldquo;.&mdash;&rdquo;,&ldquo;-.-&rdquo;,&ldquo;.-..&rdquo;,&ldquo;&ndash;&rdquo;,&ldquo;-.&rdquo;,&ldquo;&mdash;&rdquo;,&ldquo;.&ndash;.&rdquo;,&ldquo;&ndash;.-&rdquo;,&ldquo;.-.&rdquo;,&ldquo;&hellip;&rdquo;,&ldquo;-&rdquo;,&ldquo;..-&rdquo;,&ldquo;&hellip;-&rdquo;,&ldquo;.&ndash;&rdquo;,&ldquo;-..-&rdquo;,&ldquo;-.&ndash;&rdquo;,&ldquo;&ndash;..&rdquo;]</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>&quot;cab&quot;</code> can be written as <code>&quot;-.-..--...&quot;</code>, which is the concatenation of <code>&quot;-.-.&quot;</code>, <code>&quot;.-&quot;</code>, and <code>&quot;-...&quot;</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 = [&ldquo;gin&rdquo;,&ldquo;zen&rdquo;,&ldquo;gig&rdquo;,&ldquo;msg&rdquo;]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong> The transformation of each word is:</p> <p>&ldquo;gin&rdquo; -> &ldquo;&ndash;&hellip;-.&rdquo;</p> <p>&ldquo;zen&rdquo; -> &ldquo;&ndash;&hellip;-.&rdquo;</p> <p>&ldquo;gig&rdquo; -> &ldquo;&ndash;&hellip;&ndash;.&rdquo;</p> <p>&ldquo;msg&rdquo; -> &ldquo;&ndash;&hellip;&ndash;.&rdquo;</p> <p>There are 2 different transformations: &ldquo;&ndash;&hellip;-.&rdquo; and &ldquo;&ndash;&hellip;&ndash;.&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;a&rdquo;]</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 Details

    • Solution

      public Solution()
  • Method Details

    • uniqueMorseRepresentations

      public int uniqueMorseRepresentations(String[] words)