java

[프로그래머스 - 자바] 외계어 사전

tues 2023. 9. 6. 08:07

문제 설명

 

솔루션

class Solution {
    public int solution(String[] spell, String[] dic) {
        boolean word_chk = false;
        
        for(String word : dic){
            int cnt = 0;
            for(String s : spell){
                if(word.contains(s)){
                    cnt ++; //한글자씩 같을때마다 카운트
                }
            }
            if(cnt == spell.length){ //카운트가 한 단어라면 
                word_chk = true;
                break;
            }
    }
        return word_chk? 1 : 2;
    }
}