https://programmers.co.kr/learn/courses/30/lessons/43162
class Solution {
public int solution(int n, int[][] computers) {
int answer=0;
boolean[] visited = new boolean[n];
for (int i=0;i<n;i++){
answer += dfs(i,computers, visited);
}
return answer;
}
public static int dfs(int node, int[][] computers, boolean[] visited){
if (visited[node])
return 0;
visited[node] = true;
for (int i=0; i<computers.length; i++){
if (computers[node][i] == 1){
dfs(i, computers, visited);
}
}
return 1;
}
}
배열의 길이가 정해졌을 때는 List보다는 array를 사용할 것!