전체 글
-
[못풀었다/프로그래머스] 가장 먼 노드코딩테스트 2023. 6. 10. 13:54
function solution(n, edge) { var answer = 0; const graph = Array.from({length:n+1},()=>[]) for(let i=0;ifalse) const distance = Array.from({length:n+1},()=>0) bfs(graph,visited,distance) let max = Math.max(...distance) return distance.filter((el)=>el===max).length return answer; } function bfs(graph,visited,distance){ const queue = [1]; visited[1] = true; while(queue.length){ let node = queue.sh..
-
[못풀었다/프로그래머스] 불량사용자코딩테스트 2023. 6. 9. 14:30
function solution(user_id, banned_id) { const set = new Set() const banIdCopy = banned_id.slice() const selected = Array.from({length:user_id.length},()=>false) const isChecked = (bannedId,userId) => { if(bannedId.length!==userId.length) return false; else {for(let i=0;i { if (banIdCopy.length === 0) { set.add(arr.sort().join(',')); } else { for (let i = 0; i < user_id.length; i++) { if (selecte..
-
[예외처리못함/프로그래머스] 베스트앨범코딩테스트 2023. 6. 7. 17:30
function solution(genres, plays) { var answer = []; let genresPlayNumber = {}; let genresSongPlay = {}; let genresPlayNumberArr = []; for(let i=0;ib[1]-a[1]); for(let i=0;i1) arr.sort((a,b)=>b[1]-a[1]) answer.push(arr[0][0]) if(arr.length>1) answer.push(arr[1][0]) } return answer; } arr.length가 1인경우를 고려했어야 하는데 못해서 런타임에러가 계속 났었다!