最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2452. Words Within Two Edits of Dictionary

2023-05-25 12:33 作者:您是打尖兒還是住店呢  | 我要投稿

You are given two string arrays,?queries?and?dictionary. 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 from?queries?that, after a?maximum?of two edits, equal some word from?dictionary.

Return?a list of all words from?queries,?that match with some word from?dictionary?after a maximum of?two edits. Return the words in the?same order?they appear in?queries.

?

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 <= 100

  • n == queries[i].length == dictionary[j].length

  • 1 <= n <= 100

  • All?queries[i]?and?dictionary[j]?are composed of lowercase English letters.

依次去遍歷2個字符串的差異字符數(shù),如果小于等于2個,那么就放到list中,

返回即可;


Runtime:?3 ms, faster than?85.71%?of?Java?online submissions for?Words Within Two Edits of Dictionary.

Memory Usage:?42.1 MB, less than?99.40%?of?Java?online submissions for?Words Within Two Edits of Dictionary.


LeetCode 2452. Words Within Two Edits of Dictionary的評論 (共 條)

分享到微博請遵守國家法律
合阳县| 濮阳市| 大宁县| 平顶山市| 阜新市| 马龙县| 河池市| 安康市| 门头沟区| 清丰县| 乐至县| 八宿县| 栾城县| 镇远县| 灵石县| 蕲春县| 常山县| 栾川县| 青龙| 溆浦县| 皋兰县| 九龙县| 玉田县| 通海县| 辽宁省| 三门县| 从江县| 石泉县| 宜川县| 麟游县| 海城市| 乐昌市| 临夏县| 锡林郭勒盟| 鄂伦春自治旗| 大宁县| 宁海县| 镇平县| 化德县| 独山县| 桐梓县|