본문 바로가기
Algorithm/Programmers

[Programmers] Lv.0 | 외계어 사전 | Java

by unknownomad 2025. 9. 27.

문제

https://school.programmers.co.kr/learn/courses/30/lessons/120869

 

풀이

import java.util.*;

class Solution {
    public int solution(String[] spell, String[] dic) {
        boolean found = Arrays.stream(dic)
            .anyMatch(word -> {
                for (String s : spell) {
                    int count = word.length() - word.replace(s, "").length();
                    if (count != 1) {
                        return false;
                    }
                }
                return true;
            });
        return found ? 1 : 2;
    }
}

댓글