Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 백준 14391
- 백준 18290
- sort
- 백준 15661
- java 반올림
- mysql
- Math.floor()
- 프로그래머스 연속된 수의 합 java
- 프로그래머스 옹알이 java
- java
- Math.ceil()
- java 내림
- 프로그래머스 네트워크 java
- 알고리즘
- Algorithm
- 프로그래머스 도둑질 java
- 백준 16935
- time complexity
- 백준 16927
- 프로그래머스 숫자의 표현 java
- Arrays
- 백준 17425
- 코딩테스트
- 0으로 채우기
- java 올림
- 백준 11723
- 자바
- 네트워크
- 백준 4375
- Codility
Archives
- Today
- Total
취미처럼
[프로그래머스] 네트워크 본문
https://school.programmers.co.kr/learn/courses/30/lessons/43162
방문체크를 하는 visit 배열을 컴퓨터 개수 n개로 생성
각각의 컴퓨터 노드를 모두 탐색
1일때만 탐색하거나 큐에 넣어서 answer를 늘려줌
import java.util.*;
class Solution {
public int solution(int n, int[][] computers) {
int answer = 0;
boolean[] visit = new boolean[n];
for(int i = 0; i < n; i++) {
if(!visit[i]) {
dfs(computers, visit, i);
answer++;
}
}
return answer;
}
public void dfs(int[][] computers, boolean[] visit, int start) {
visit[start] = true;
for(int i=0; i < computers.length; i++) {
if(!visit[i] && computers[start][i] == 1) {
dfs(computers, visit, i);
}
}
}
}
'Algorithm > Programmers' 카테고리의 다른 글
[프로그래머스] 연속된 수의 합 (0) | 2021.03.15 |
---|---|
[프로그래머스] 옹알이 (0) | 2021.03.15 |
[프로그래머스] 숫자의 표현 (0) | 2021.03.15 |
[프로그래머스] 도둑질 (0) | 2021.03.08 |
Comments