class Solution {
public int solution(String[] spell, String[] dic) {
int answer = 2;
for (int i = 0; i < dic.length; i++) {
int cnt=0;
boolean[] visited = new boolean[spell.length];
for (int j = 0; j < spell.length; j++) {
for (int k = 0; k < dic[i].length(); k++) {
if (spell[j].charAt(0) == dic[i].charAt(k)&&!visited[j]) {
visited[j]=true;
break;
}
}
if (visited[j] == false) {
break;
}
}
for (boolean b : visited) {
if (b == true) {
cnt++;
}else {
break;
}
}
if (cnt == spell.length) {
return 1;
}
}
return answer;
}
}