1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/唯一摩尔斯密码词 [unique-morse-code-words].html
2022-03-29 12:43:11 +08:00

55 lines
1.8 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>国际摩尔斯密码定义一种标准编码方式,将每个字母对应于一个由一系列点和短线组成的字符串,&nbsp;比如:</p>
<ul>
<li><code>'a'</code> 对应 <code>".-"</code> </li>
<li><code>'b'</code> 对应 <code>"-..."</code> </li>
<li><code>'c'</code> 对应 <code>"-.-."</code> ,以此类推。</li>
</ul>
<p>为了方便,所有 <code>26</code> 个英文字母的摩尔斯密码表如下:</p>
<pre>
[".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","...","-","..-","...-",".--","-..-","-.--","--.."]</pre>
<p>给你一个字符串数组 <code>words</code> ,每个单词可以写成每个字母对应摩尔斯密码的组合。</p>
<ul>
<li>例如,<code>"cab"</code> 可以写成 <code>"-.-..--..."</code> (即 <code>"-.-."</code> + <code>".-"</code> + <code>"-..."</code> 字符串的结合)。我们将这样一个连接过程称作 <strong>单词翻译</strong></li>
</ul>
<p><strong> </strong><code>words</code> 中所有单词进行单词翻译,返回不同 <strong>单词翻译</strong> 的数量。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong> words = ["gin", "zen", "gig", "msg"]
<strong>输出:</strong> 2
<strong>解释: </strong>
各单词翻译如下:
"gin" -&gt; "--...-."
"zen" -&gt; "--...-."
"gig" -&gt; "--...--."
"msg" -&gt; "--...--."
共有 2 种不同翻译, "--...-." 和 "--...--.".
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>words = ["a"]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= words.length &lt;= 100</code></li>
<li><code>1 &lt;= words[i].length &lt;= 12</code></li>
<li><code>words[i]</code> 由小写英文字母组成</li>
</ul>