programmers_네트워크_java
2023. 2. 27. 18:03ㆍAlgorithm/Programmers
728x90
https://school.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++){
if(!visited[i]){
answer++;
visited[i] = true;
dfs(n, computers, i, visited);
}
}
return answer;
}
public void dfs(int n, int[][] computers, int nowNode, boolean[] visited){
for(int i = 0; i<n; i++){
if(computers[nowNode][i] == 1 && !visited[i]){
visited[i] = true;
dfs(n, computers, i, visited);
}
}
}
}
'Algorithm > Programmers' 카테고리의 다른 글
programmers_최고의 집합_java (0) | 2023.02.28 |
---|---|
programmers_단어 변환_java (0) | 2023.02.27 |
programmers_최솟값 만들기_java (0) | 2023.02.27 |
programmers_올바른 괄호_java (0) | 2023.02.27 |
programmers_JadenCase 문자열 만들기_java (0) | 2023.02.27 |