09-06. DFS(깊이 우선 탐색)
0. 문제 유형
1. 네트워크
import java.util.*;
class Solution {
public int solution(int n, int[][] computers) {
int answer = 0;
boolean[] check = new boolean[n];
for (int i = 0; i < n; i++) {
if(!check[i]) {
dfs(computers, i, check);
answer++;
}
}
return answer;
}
public void dfs(int[][] computers, int i, boolean[] check) {
check[i] = true;
for(int j = 0; j < computers.length; j++) {
if (i != j && computers[i][j] == 1 && !check[j]) {
dfs(computers, j, check);
}
}
}
}2. 단어 변환
3. 여행 경로
4. 불량사용자
5. 다단계 칫솔 판매
Last updated