Notice
Recent Posts
Recent Comments
Link
S E P H ' S
[Python] 네트워크 본문
from collections import deque
def solution(n, computers):
answer = 0
visited = [False] * n
for i in range(n):
if not visited[i]:
bfs(i, computers, visited)
answer += 1
return answer
def bfs(start, computers, visited):
q = deque([start])
while q:
cur = q.popleft()
if not visited[cur]:
visited[cur] = True
for next in range(len(computers)):
if next == cur or computers[cur][next] == 0:
continue
elif not visited[next]:
q.append(next)
'Algorithm > Programmers' 카테고리의 다른 글
[Python] 여행 경로 (0) | 2021.08.07 |
---|---|
[Python] 단어 변환 (0) | 2021.08.07 |
[Python] 땅따먹기 (0) | 2021.07.31 |
[Python] 숫자의 표현 (0) | 2021.07.31 |
[Python] 최댓값과 최솟값 (0) | 2021.07.31 |