{"id":220,"date":"2018-09-08T19:40:26","date_gmt":"2018-09-08T11:40:26","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=220"},"modified":"2018-11-29T14:41:26","modified_gmt":"2018-11-29T06:41:26","slug":"804-unique-morse-code-words","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=220","title":{"rendered":"804. Unique Morse Code Words"},"content":{"rendered":"<p>International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows:\u00a0<code>\"a\"<\/code>\u00a0maps to\u00a0<code>\".-\"<\/code>,\u00a0<code>\"b\"<\/code>maps to\u00a0<code>\"-...\"<\/code>,\u00a0<code>\"c\"<\/code>\u00a0maps to\u00a0<code>\"-.-.\"<\/code>, and so on.<\/p>\n<p>For convenience, the full table for the 26 letters of the English alphabet is given below:<\/p>\n<pre>[\".-\",\"-...\",\"-.-.\",\"-..\",\".\",\"..-.\",\"--.\",\"....\",\"..\",\".---\",\"-.-\",\".-..\",\"--\",\"-.\",\"---\",\".--.\",\"--.-\",\".-.\",\"...\",\"-\",\"..-\",\"...-\",\".--\",\"-..-\",\"-.--\",\"--..\"]<\/pre>\n<p>Now, given a list of words, each word can be written as a concatenation of the Morse code of each letter. For example, &#8220;cba&#8221; can be written as &#8220;-.-..&#8211;&#8230;&#8221;, (which is the concatenation &#8220;-.-.&#8221; + &#8220;-&#8230;&#8221; + &#8220;.-&#8220;). We&#8217;ll call such a concatenation, the transformation\u00a0of a word.<\/p>\n<p>Return the number of different transformations among all words we have.<\/p>\n<pre><strong>Example:<\/strong>\r\n<strong>Input:<\/strong> words = [\"gin\", \"zen\", \"gig\", \"msg\"]\r\n<strong>Output:<\/strong> 2\r\n<strong>Explanation: <\/strong>\r\nThe transformation of each word is:\r\n\"gin\" -&gt; \"--...-.\"\r\n\"zen\" -&gt; \"--...-.\"\r\n\"gig\" -&gt; \"--...--.\"\r\n\"msg\" -&gt; \"--...--.\"\r\n\r\nThere are 2 different transformations, \"--...-.\" and \"--...--.\".\r\n<\/pre>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li>The length of\u00a0<code>words<\/code>\u00a0will be at most\u00a0<code>100<\/code>.<\/li>\n<li>Each\u00a0<code>words[i]<\/code>\u00a0will have length in range\u00a0<code>[1, 12]<\/code>.<\/li>\n<li><code>words[i]<\/code>\u00a0will only consist of lowercase letters.<\/li>\n<\/ul>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def uniqueMorseRepresentations(self, words):\r\n        &quot;&quot;&quot;\r\n        :type words: List[str]\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        a = [&quot;.-&quot;,&quot;-...&quot;,&quot;-.-.&quot;,&quot;-..&quot;,&quot;.&quot;,&quot;..-.&quot;,&quot;--.&quot;,&quot;....&quot;,&quot;..&quot;,&quot;.---&quot;,&quot;-.-&quot;,&quot;.-..&quot;,&quot;--&quot;,&quot;-.&quot;,&quot;---&quot;,&quot;.--.&quot;,&quot;--.-&quot;,&quot;.-.&quot;,&quot;...&quot;,&quot;-&quot;,&quot;..-&quot;,&quot;...-&quot;,&quot;.--&quot;,&quot;-..-&quot;,&quot;-.--&quot;,&quot;--..&quot;]\r\n        d = {}\r\n        for word in words:\r\n            temp_key = &quot;&quot;\r\n            for w in word:\r\n                temp_key += a[ord(w)-97]\r\n            d[temp_key] = 1\r\n        return len(d)\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>International Morse Code defines a standard encoding wh<a href=\"https:\/\/www.ccagml.com\/?p=220\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">804. Unique Morse Code Words<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/220"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":221,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions\/221"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}