[LeetCode] Concatenated Words 连接单词
Posted Grandyang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[LeetCode] Concatenated Words 连接单词相关的知识,希望对你有一定的参考价值。
Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words.
A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.
Example:
Input: ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"] Output: ["catsdogcats","dogcatsdog","ratcatdogcat"] Explanation: "catsdogcats" can be concatenated by "cats", "dog" and "cats";
"dogcatsdog" can be concatenated by "dog", "cats" and "dog";
"ratcatdogcat" can be concatenated by "rat", "cat", "dog" and "cat".
Note:
- The number of elements of the given array will not exceed
10,000
- The length sum of elements in the given array will not exceed
600,000
. - All the input string will only include lower case letters.
- The returned elements order does not matter.
s
以上是关于[LeetCode] Concatenated Words 连接单词的主要内容,如果未能解决你的问题,请参考以下文章
[LeetCode] Concatenated Words 连接单词
leetcode472. Concatenated Words
[LeetCode] 1239. Maximum Length of a Concatenated String with Unique Characters