티스토리 뷰

import java.util.*;

class Solution {
    public String solution(String[] participant, String[] completion) {
       String fail = "";
       HashMap <String, Integer> answer = new HashMap<>();
       int value = 0;
        
        for(int i = 0; i< participant.length; i++){
            if(answer.containsKey(participant[i])){
                value = answer.get(participant[i]);
                answer.put(participant[i], value + 1);
            }else{
                answer.put(participant[i], 1 );
            }   
        }
        
        for(int i = 0; i < completion.length; i++){
            if(answer.containsKey(completion[i])){
                value = answer.get(completion[i]);
                answer.put(completion[i], value - 1);
            }
        }
        
        for(String key : answer.keySet()){
            if(answer.get(key) == 1){
                fail = key;
            }
        }
        
        return fail;
        
    }
}