Skip to content

Commit ab0554e

Browse files
committed
solve : programmers 네트워크
1 parent ed57e46 commit ab0554e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const solution = (n, computers) => {
2+
let answer = 0;
3+
const network = Array.from({ length: n }, () => 0);
4+
5+
for (let i = 0; i < n; i += 1) {
6+
if (network[i] !== 0) continue;
7+
answer += 1;
8+
network[i] = answer;
9+
10+
const queue = [i];
11+
while (queue.length > 0) {
12+
const visit = queue.pop();
13+
computers[visit].forEach((computer, index) => {
14+
if (computer && network[index] === 0) {
15+
queue.push(index);
16+
network[index] = answer;
17+
}
18+
});
19+
}
20+
}
21+
22+
return answer;
23+
};

src/do02reen24/Review/week15.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@
99
## :ballot_box_with_check: 프로그래머스 영어 끝말잇기(12981)
1010

1111
- 각 경우를 고려하여 처리해주었다.
12+
13+
## :ballot_box_with_check: 프로그래머스 네트워크(43162)
14+
15+
- BFS의 개념을 활용하여 풀었다.
16+
- 백준 2644번 문제와 비슷한 것 같다.

0 commit comments

Comments
 (0)