1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/元音拼写检查器 [vowel-spellchecker].html
2022-03-29 12:43:11 +08:00

58 lines
3.0 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;<code>wordlist</code>&nbsp;的情况下,我们希望实现一个拼写检查器,将查询单词转换为正确的单词。</p>
<p>对于给定的查询单词&nbsp;<code>query</code>,拼写检查器将会处理两类拼写错误:</p>
<ul>
<li>大小写:如果查询匹配单词列表中的某个单词(<strong>不区分大小写</strong>),则返回的正确单词与单词列表中的大小写相同。
<ul>
<li>例如:<code>wordlist = ["yellow"]</code>, <code>query = "YellOw"</code>: <code>correct = "yellow"</code></li>
<li>例如:<code>wordlist = ["Yellow"]</code>, <code>query = "yellow"</code>: <code>correct = "Yellow"</code></li>
<li>例如:<code>wordlist = ["yellow"]</code>, <code>query = "yellow"</code>: <code>correct = "yellow"</code></li>
</ul>
</li>
<li>元音错误:如果在将查询单词中的元音 <code>('a', 'e', 'i', 'o', 'u')</code>&nbsp;&nbsp;分别替换为任何元音后,能与单词列表中的单词匹配(<strong>不区分大小写</strong>),则返回的正确单词与单词列表中的匹配项大小写相同。
<ul>
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yollow"</code>: <code>correct = "YellOw"</code></li>
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yeellow"</code>: <code>correct = ""</code> (无匹配项)</li>
<li>例如:<code>wordlist = ["YellOw"]</code>, <code>query = "yllw"</code>: <code>correct = ""</code> (无匹配项)</li>
</ul>
</li>
</ul>
<p>此外,拼写检查器还按照以下优先级规则操作:</p>
<ul>
<li>当查询完全匹配单词列表中的某个单词(<strong>区分大小写</strong>)时,应返回相同的单词。</li>
<li>当查询匹配到大小写问题的单词时,您应该返回单词列表中的第一个这样的匹配项。</li>
<li>当查询匹配到元音错误的单词时,您应该返回单词列表中的第一个这样的匹配项。</li>
<li>如果该查询在单词列表中没有匹配项,则应返回空字符串。</li>
</ul>
<p>给出一些查询 <code>queries</code>,返回一个单词列表 <code>answer</code>,其中 <code>answer[i]</code> 是由查询 <code>query = queries[i]</code> 得到的正确单词。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>wordlist = ["KiTe","kite","hare","Hare"], queries = ["kite","Kite","KiTe","Hare","HARE","Hear","hear","keti","keet","keto"]
<strong>输出:</strong>["kite","KiTe","KiTe","Hare","hare","","","KiTe","","KiTe"]</pre>
<p><strong>示例 2:</strong></p>
<pre>
<b>输入:</b>wordlist = ["yellow"], queries = ["YellOw"]
<b>输出:</b>["yellow"]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= wordlist.length, queries.length &lt;= 5000</code></li>
<li><code>1 &lt;= wordlist[i].length, queries[i].length &lt;= 7</code></li>
<li><code>wordlist[i]</code>&nbsp;&nbsp;<code>queries[i]</code>&nbsp;只包含英文字母</li>
</ul>