✨ 정답 ✨
function solution( n, lost, reserve){
let canLend = reserve.filter((el)=>!lost.includes(el));
let needLend = lost.filter((el)=>!reserve.includes(el));
canLend.sort();
needLend.sort();
let answer=n-needLend.length;
let count=0;
for (let i=0;i<canLend.length;i++){
if (needLend.includes(canLend[i]-1)){
needLend=needLend.filter((el)=>{return el!==canLend[i]-1})
count+=1;
}else if (needLend.includes(canLend[i]+1)){
needLend=needLend.filter((el)=>{return el!==canLend[i]+1})
count+=1;
}
}
return answer+count;
}
🧵 참고한 정답지 🧵
💡💡 기억해야 할 점 💡💡