문제 : 프로그래머스 - 해시 > 완주하지 못한 선수
풀이(python)
import collections
def solution(participant, completion):
answer = collections.Counter(participant) - collections.Counter(completion)
answer = list(answer.keys())
return answer[0]
다른 코드(js)
function solution(participant, completion) {
const map = new Map();
for (let i = 0 ; i < participant.length ; i++){
let participantName = participant[i];
let completionName = completion[i];
map.set(participant[i], (map.get(participant[i]) || 0) + 1);
map.set(completion[i], (map.get(completion[i]) || 0) - 1);
}
for (let [k, v] of map){
if (v > 0) return k;
}
}