문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
문자열 배열 words가 주어졌을 때, 다른 단어의 부분 문자열인 words에서 모든 문자열을 반환해라.
#1
Input: words = ["mass", "as", "hero", "superhero"]
Output: ["as", "hero"]
Explanation: "as"는 "mass"의 부분 문자열이고 "hero"는 "superhero"의 부분 문자열이다.
#2
Input: words = ["leetcode", "et", "code"]
Output: ["et", "code"]
Explanation: "et", "code"는 "leetcode"의 부분 문자열이다.
#3
Input: words = ["blue", "green", "bu"]
Output: []
Explanation: 다른 문자열의 부분 문자열이 없다.
class Solution {
public List<String> stringMatching(String[] words) {
int l = words.length;
List<String> result = new ArrayList<>();
for(int i = 0; i < l; i++){
for(int j = 0; j < l; j++){
if(i != j && words[j].contains(words[i])){
result.add(words[i]);
break;
}
}
}
return result;
}
}