Skip to content

Commit 6dfca51

Browse files
authored
Create 1408-string-matching-in-an-array.js
1 parent 590f5ee commit 6dfca51

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

1408-string-matching-in-an-array.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {string[]} words
3+
* @return {string[]}
4+
*/
5+
const stringMatching = function(words) {
6+
const res = [], n = words.length
7+
for(let i = 0; i < n; i++) {
8+
const cur = words[i]
9+
for(let j = 0; j < n; j++) {
10+
if(i !== j && words[j].indexOf(cur) !== -1) {
11+
res.push(cur);
12+
break
13+
}
14+
}
15+
}
16+
return res
17+
};

0 commit comments

Comments
 (0)