class Solution {
public int solution(String[] spell, String[] dic) {
boolean wordCheck = false;
for (String word : dic) {
int count = 0;
for (String s : spell) {
if (word.contains(s)) count++;
}
if (count == spell.length) {
wordCheck = true;
break;
}
}
return wordCheck ? 1 : 2;
}
}
두 배열을 입력받아 spell
배열의 단어가 모두 포함된 dic
속 단어가 있는지 찾는 문제이다.
단어를 하나씩 가져와서 문자열안에 해당 문자가 있는지 확인하고 spell
배열의 길이만큼
즉 배열의 모든 단어가 있으면 boolean 값을 가지는 wordCheck를 true값으로 바꿔준다.