Class Solution
- java.lang.Object
-
- g2401_2500.s2452_words_within_two_edits_of_dictionary.Solution
-
public class Solution extends Object
2452 - Words Within Two Edits of Dictionary.Medium
You are given two string arrays,
queriesanddictionary. All words in each array comprise of lowercase English letters and have the same length.In one edit you can take a word from
queries, and change any letter in it to any other letter. Find all words fromqueriesthat, after a maximum of two edits, equal some word fromdictionary.Return a list of all words from
queries, that match with some word fromdictionaryafter a maximum of two edits. Return the words in the same order they appear inqueries.Example 1:
Input: queries = [“word”,“note”,“ants”,“wood”], dictionary = [“wood”,“joke”,“moat”]
Output: [“word”,“note”,“wood”]
Explanation:
-
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”].
Example 2:
Input: queries = [“yes”], dictionary = [“not”]
Output: []
Explanation:
Applying any two edits to “yes” cannot make it equal to “not”. Thus, we return an empty array.
Constraints:
1 <= queries.length, dictionary.length <= 100n == queries[i].length == dictionary[j].length1 <= n <= 100- All
queries[i]anddictionary[j]are composed of lowercase English letters.
-
-
-
Constructor Summary
Constructors Constructor Description Solution()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>twoEditWords(String[] queries, String[] dictionary)
-