-심심풀이 코딩테스트

  • 완주하지 못한 선수
import java.util.HashMap;

class Solution {
    public String solution(String[] participant, String[] completion) {
        HashMap<String, Integer> participantMap = new HashMap<>();
        
        if(participant == null || completion == null)
            throw new IllegalArgumentException("파라메터 배열이 null입니다.");
        
        for(int i=0; i < participant.length; i++) {
            String key = participant[i];
            if(participantMap.containsKey(key))
                participantMap.put(key, participantMap.get(key) + 1);
            else
                participantMap.put(key, 1);
        }
               
        for(int i=0; i < completion.length; i++) {
            String key = completion[i];
            if(participantMap.containsKey(key) && participantMap.get(key) > 1)
                participantMap.put(key, participantMap.get(key) - 1);
            else 
                participantMap.remove(key);
        }
        
        return participantMap.keySet()
                .stream()
                .findFirst()
                .orElse("");
    }
}
  • dd
  • ddd