
function solution(n, computers) {
var answer = n;
const visited = Array(n).fill(0);
const checkLinkedComputers = (computer)=>{
visited[computer] = 1;
for(let j=0; j<n; j++){
if(visited[j]===1) continue;
const isLinkedComputer = computers[computer][j];
if(isLinkedComputer){
visited[j]=1;
checkLinkedComputers(j);
answer--;
}
}
}
for(let i=0; i<n; i++){
checkLinkedComputers(i);
}
return answer;
}
find union (?)

function solution(n, computers) {
const findUnion = () => {
const visited = [];
let count = 0;
const dfs = (vertex, isStart) => {
if(visited[vertex]){
return;
}
visited[vertex] =1;
computers[vertex].forEach((neighbor, vertex) => neighbor && dfs(vertex, false));
isStart && count++;
}
for(let i=0; i<computers.length; i++){
dfs(i, true);
}
return count;
}
return findUnion();
}