1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public List<String> stringMatching(String[] words) { List<String> resultList = new ArrayList<>();
for (int i = 0; i < words.length; i++) { for (int j = 0; j < words.length; j++) { if (i == j) { continue; }
if (words[j].contains(words[i])) { resultList.add(words[i]); break; } } }
return resultList; } }
|
References
1408. String Matching in an Array