코린이의 정석 그자체로 풀음
function solution(participant, completion) {
var answer = '';
participant.sort()
completion.sort()
for(let i=0;i<participant.length;i++){
if(completion[i]!==participant[i]){
answer=participant[i]
break
}
}
return answer;
}
효율성을 더 고려해서 Map 으로 풀은 다른사람풀이
function solution(participant, completion) {
const map = new Map();
for(let i = 0; i < participant.length; i++) {
let a = participant[i],
b = completion[i];
map.set(a, (map.get(a) || 0) + 1);
map.set(b, (map.get(b) || 0) - 1);
}
console.log(map)
for(let [k, v] of map) {
if(v > 0) return k;
}
return 'nothing';
}
입출력예
console.log(map)하면 이렇게뜸
completion에 vinko가 없으므로, -1을 못함. 그래서 1로 유지..!