알고리즘/프로그래머스
외계인 사전.
prime9999
2023. 5. 31. 17:03
300x250
public static int alienEncyclopedia(String[] spell, String[] dic) {
int cnt = 0;
//비교 값
for(String d : dic){
//스펠링이 모두 포함되어 있다면 정지.
if(spell.length == cnt) break;
//스펠링 배열
for(String s : spell){
if(d.contains(s)){
//일치하면 count
++cnt;
}else{
//한개라도 일치하지 않으면 정지.
cnt = 0;
break;
}
}
}
return (cnt == spell.length)?1:2;
}
728x90