rustgym/leetcode/
_1408_string_matching_in_an_array.rs1struct Solution;
2
3impl Solution {
4 fn string_matching(words: Vec<String>) -> Vec<String> {
5 let n = words.len();
6 let mut res = vec![];
7 for i in 0..n {
8 let mut found = false;
9 for j in 0..n {
10 if !found && i != j && words[j].contains(&words[i]) {
11 found = true;
12 }
13 }
14 if found {
15 res.push(words[i].to_string());
16 }
17 }
18 res
19 }
20}
21
22#[test]
23fn test() {
24 let words = vec_string!["mass", "as", "hero", "superhero"];
25 let res = vec_string!["as", "hero"];
26 assert_eq!(Solution::string_matching(words), res);
27 let words = vec_string!["leetcode", "et", "code"];
28 let res = vec_string!["et", "code"];
29 assert_eq!(Solution::string_matching(words), res);
30 let words = vec_string!["blue", "green", "bu"];
31 let res = vec_string![];
32 assert_eq!(Solution::string_matching(words), res);
33}