472. Concatenated Words Hard

@problem@discussion
#Array#String#Dynamic Programming#Depth-First Search#Trie



1/**
2 * [472] Concatenated Words
3 *
4 * Given an array of strings words (without duplicates), return all the concatenated words in the given list of words.
5 * A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.
6 *  
7 * Example 1:
8 * 
9 * Input: words = ["cat","cats","catsdogcats","dog","dogcatsdog","hippopotamuses","rat","ratcatdogcat"]
10 * Output: ["catsdogcats","dogcatsdog","ratcatdogcat"]
11 * Explanation: "catsdogcats" can be concatenated by "cats", "dog" and "cats"; 
12 * "dogcatsdog" can be concatenated by "dog", "cats" and "dog"; 
13 * "ratcatdogcat" can be concatenated by "rat", "cat", "dog" and "cat".
14 * Example 2:
15 * 
16 * Input: words = ["cat","dog","catdog"]
17 * Output: ["catdog"]
18 * 
19 *  
20 * Constraints:
21 * 
22 * 	1 <= words.length <= 10^4
23 * 	1 <= words[i].length <= 30
24 * 	words[i] consists of only lowercase English letters.
25 * 	All the strings of words are unique.
26 * 	1 <= sum(words[i].length) <= 10^5
27 * 
28 */
29pub struct Solution {}
30
31// problem: https://leetcode.com/problems/concatenated-words/
32// discuss: https://leetcode.com/problems/concatenated-words/discuss/?currentPage=1&orderBy=most_votes&query=
33
34// submission codes start here
35
36impl Solution {
37    pub fn find_all_concatenated_words_in_a_dict(words: Vec<String>) -> Vec<String> {
38        vec![]
39    }
40}
41
42// submission codes end
43
44#[cfg(test)]
45mod tests {
46    use super::*;
47
48    #[test]
49    fn test_472() {
50    }
51}
52


Back
© 2025 bowen.ge All Rights Reserved.