class Solution {
static boolean[] visit;
static int num;
static int[][] comInfo;
public int solution(int n, int[][] computers) {
int answer = 0;
visit = new boolean[n];
num = n;
comInfo = computers;
for(int i=0; i< num; i++){
if(!visit[i]){
dfs(i);
answer++;
}
}
return answer;
}
static void dfs(int x){
visit[x] = true;
for(int i=0; i<num; i++){
if(i!=x && !visit[i] && comInfo[x][i] == 1){
dfs(i);
}
}
}
}
'공부기록 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 카드 뭉치 (0) | 2023.10.15 |
---|---|
[프로그래머스] MySQL (정리중) (0) | 2023.10.13 |
[프로그래머스] 예산 (0) | 2023.09.21 |
[프로그래머스] 두 개 뽑아서 더하기 (0) | 2023.09.17 |
[프로그래머스] 짝지어 제거하기 (0) | 2023.09.16 |