mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-11 02:58:13 +08:00
39 lines
2.3 KiB
HTML
39 lines
2.3 KiB
HTML
<p>You are given two string arrays, <code>queries</code> and <code>dictionary</code>. All words in each array comprise of lowercase English letters and have the same length.</p>
|
|
|
|
<p>In one <strong>edit</strong> you can take a word from <code>queries</code>, and change any letter in it to any other letter. Find all words from <code>queries</code> that, after a <strong>maximum</strong> of two edits, equal some word from <code>dictionary</code>.</p>
|
|
|
|
<p>Return<em> a list of all words from </em><code>queries</code><em>, </em><em>that match with some word from </em><code>dictionary</code><em> after a maximum of <strong>two edits</strong></em>. Return the words in the <strong>same order</strong> they appear in <code>queries</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> queries = ["word","note","ants","wood"], dictionary = ["wood","joke","moat"]
|
|
<strong>Output:</strong> ["word","note","wood"]
|
|
<strong>Explanation:</strong>
|
|
- Changing the 'r' in "word" to 'o' allows it to equal the dictionary word "wood".
|
|
- Changing the 'n' to 'j' and the 't' to 'k' in "note" changes it to "joke".
|
|
- It would take more than 2 edits for "ants" to equal a dictionary word.
|
|
- "wood" can remain unchanged (0 edits) and match the corresponding dictionary word.
|
|
Thus, we return ["word","note","wood"].
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> queries = ["yes"], dictionary = ["not"]
|
|
<strong>Output:</strong> []
|
|
<strong>Explanation:</strong>
|
|
Applying any two edits to "yes" cannot make it equal to "not". Thus, we return an empty array.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>1 <= queries.length, dictionary.length <= 100</code></li>
|
|
<li><code>n == queries[i].length == dictionary[j].length</code></li>
|
|
<li><code>1 <= n <= 100</code></li>
|
|
<li>All <code>queries[i]</code> and <code>dictionary[j]</code> are composed of lowercase English letters.</li>
|
|
</ul>
|