
[프로그래머스] 43162 네트워크(Lv.3) - BFS
·
코딩 테스트/알고리즘
문제네트워크예제1예제2코드시도 1 - Xcomputers가 2차원 배열이라서 단순히 1인 노드가 연결된 뭉치의 개수를 구하는 문제로 잘못 이해했다.시도 2로...import java.util.*;class Solution { boolean[][] visited; int[] dx = {1, -1, 0, 0}; int[] dy = {0, 0, 1, -1}; public int solution(int n, int[][] computers) { visited = new boolean[n][n]; int cnt = 0; for (int i = 0; i q = new LinkedList(); q.offer(new int[] {x, y}); ..