File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
Original file line number Diff line number Diff line change 99## :ballot_box_with_check : 프로그래머스 영어 끝말잇기(12981)
1010
1111- 각 경우를 고려하여 처리해주었다.
12+
13+ ## :ballot_box_with_check : 프로그래머스 네트워크(43162)
14+
15+ - BFS의 개념을 활용하여 풀었다.
16+ - 백준 2644번 문제와 비슷한 것 같다.
You can’t perform that action at this time.
0 commit comments