프로그래머스 - 체육복(Greedy) [JS]
·
알고리즘(Algorithm)
풀이 function solution(n, lost, reserve) { let checkLost=lost.filter(i=>!reserve.includes(i)).sort() let checkReserve=reserve.filter(i=>!lost.includes(i)).sort() checkLost=checkLost.filter(i=>{ let temp=checkReserve.find(j=>Math.abs(i-j)k!==temp) }) return n-checkLost.length } lost와 reserve에 둘 다 있는 숫자를 먼저 제거후 정렬-> 체육복을 잃어버렸지만 여분을 가진 친구들 ex) solution(3, [1], [1]) 체육복을 잃어버린 학생들의 배열 ( checkLost )의 값이..