Skip to content

Commit 8b49e00

Browse files
committed
Programmers_43162 : 네트워크
1 parent 6006987 commit 8b49e00

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class Solution {
2+
3+
private boolean[] visited;
4+
5+
public int solution(int n, int[][] computers) {
6+
int count = 0;
7+
visited = new boolean[n];
8+
for(int i=0; i<n; i++) {
9+
if(!visited[i]) {
10+
count++;
11+
dfs(computers, i);
12+
}
13+
}
14+
return count;
15+
}
16+
17+
public void dfs(int[][] computers, int v) {
18+
int len = computers.length;
19+
for(int i=0; i<len; i++) {
20+
if(!visited[i] && computers[v][i] == 1) {
21+
visited[i] = true;
22+
dfs(computers, i);
23+
}
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)