https://school.programmers.co.kr/learn/courses/30/lessons/43162
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
def solution(n, computers):
def dfs(node):
visited[node] = True
for neighbor in range(n):
if computers[node][neighbor] == 1 and not visited[neighbor]:
dfs(neighbor)
visited = [False] * n # 방문 여부를 기록하는 리스트
network_count = 0
for i in range(n):
if not visited[i]: # 방문하지 않은 컴퓨터를 탐색
dfs(i)
network_count += 1 # 새로운 네트워크 발견 시 증가
return network_count
'프로그래머스' 카테고리의 다른 글
[Python/파이썬]프로그래머스 87694. 아이템 줍기 (0) | 2025.01.19 |
---|---|
[Python/파이썬]프로그래머스 86491. 최소직사각형 (0) | 2025.01.18 |
프로그래머스 87946. 피로도 (0) | 2025.01.18 |
프로그래머스 43163. 단어 변환 (0) | 2025.01.17 |
프로그래머스 1844. 게임 맵 최단거리 (0) | 2025.01.17 |