We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6006987 commit 8b49e00Copy full SHA for 8b49e00
week9/Programmers_43162(네트워크).java
@@ -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
23
24
25
26
+}
0 commit comments