GaGe

[프로그래머스] 네트워크 - java 본문

알고리즘/[2020] 프로그래머스

[프로그래머스] 네트워크 - java

Sorrel 2020. 6. 2. 16:36
class Solution {
    public boolean[] visited;
    public void dps(int n, int[][] computers, int i ){
        visited[i]=true;
        for(int j =0; j<n; j++){
            if((visited[j]==false)&&(computers[i][j]==1)){
                dps(n, computers, j);
            }
        }
    }
    public int solution(int n, int[][] computers) {
        int answer=0;
        visited= new boolean[n];
        for(int i =0; i<n ; i++){
            if(visited[i]==false){
                answer++;
                dps(n, computers, i);
            }
        }
        return answer;
    }
    
}
Comments