You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package algo;
import java.util.*;
public class Solution {
int current = 0;
public int solution(int n, int[][] computers)
{
Set<Integer> count = new HashSet<>();
int[] record = new int[n];
for (int i = 0; i < n; i++)
{
record[i] = -1;
}
for (int i = 0; i < n; i++)
{
search(i,computers,record);
current++;
}
for (int i = 0; i < n; i++) {
if (record[i] != -1)
{
count.add(record[i]);
}
}
return count.size();
}
public void search(int index,int[][] computers,int[] record)
{
for (int i = 0; i < computers[index].length; i++)
{
//연결이되어있으면
if (computers[index][i] == 1 && record[i]==-1) {
record[i] = current;
if (i != index)
{
search(i,computers,record);
}
}
}
}
}
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: