# LeetCode 1408. String Matching in an Array()-其他

## LeetCode 1408. String Matching in an Array()

### 链接

https://leetcode.cn/problems/string-matching-in-an-array/

### 示例

[“hero”,”as”] 也是有效的答案。

### 提示

1 <= words.length <= 100
1 <= words[i].length <= 30
words[i] 仅包含小写英文字母。

### 复杂度分析

``````时间复杂度 O(n2m2)

``````

### 代码

Java

``````    public List<String> stringMatching(String[] words) {
List<String> ans = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < words.length; j++) {
if (i != j && words[j].contains(words[i])) {
break;
}
}
}
return ans;
}
``````
————————

### 链接

https://leetcode.cn/problems/string-matching-in-an-array/

### 示例

[“hero”,”as”] 也是有效的答案。

### 提示

1 <= words.length <= 100
1 <= words[i].length <= 30
words[i] 仅包含小写英文字母。

### 复杂度分析

``````时间复杂度 O(n2m2)

``````

### 代码

Java

``````    public List<String> stringMatching(String[] words) {
List<String> ans = new ArrayList<>();
for (int i = 0; i < words.length; i++) {
for (int j = 0; j < words.length; j++) {
if (i != j && words[j].contains(words[i])) {