✨ 정답 ✨
function solution(n, computers) {
let answer=0;
let graph=Array.from({length: n}, ()=>new Array());
for (let i=0;i<n;i++){
for (let j=0;j<n;j++){
if (computers[i][j]===1){
graph[i].push(j);
}
}
}
console.log(graph)
let visited=new Array(n).fill(false);
for (let i=0;i<n;i++){
if (visited[i]===false){
answer+=1;
}
let next=graph[i];
while(next.length>0){
let current=next.shift();
if (visited[current]===false){
visited[current]=true;
next=[...next, ...graph[current]]
}
}
}
return answer;
}
🧵 참고한 정답지 🧵
💡💡 기억해야 할 점 💡💡