(String[] words)
| 1 | // build in method |
| 2 | class Solution { |
| 3 | public List<String> stringMatching(String[] words) { |
| 4 | List<String> res = new ArrayList<>(); |
| 5 | int n = words.length; |
| 6 | for (int i = 0;i < n;i++) { |
| 7 | |
| 8 | for (int j = 0;j < n;j++) { |
| 9 | if (i == j || words[i].length() > words[j].length()) continue; |
| 10 | |
| 11 | if (words[j].contains(words[i])) { |
| 12 | res.add(words[i]); |
| 13 | break; |
| 14 | } |
| 15 | } |
| 16 | |
| 17 | } |
| 18 | |
| 19 | return res; |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // custom compare method |
nothing calls this directly
no test coverage detected