Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
40 lines (31 loc) · 934 Bytes

File metadata and controls

40 lines (31 loc) · 934 Bytes
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
문제링크 : https://programmers.co.kr/learn/courses/30/lessons/43162?language=python3
입력예시
n
3
3
computers
[[1, 1, 0], [1, 1, 0], [0, 0, 1]]
[[1, 1, 0], [1, 1, 1], [0, 1, 1]]
출력예시
return
2
1
하루 넘게 고민하다 결국 다른사람 풀이 참고해서 풀었다..
"""
def soluction(n, computers):
answer = 0
visted = [False] * n
for node in range(n):
if (visted[node] == False):
dfs(n, computers, node, visted)
answer += 1
return answer
def dfs(n, computers, node, visted):
visted[node] = True
for childNode in range(n):
# 아직 방문하지 않은 노드이며 연결이 되어 있다면
if (visted[childNode] == False and computers[node][childNode] == 1):
# 새로운 노드 방문해서 그 노드와 연결되어 있는 다른 노드 탐색
dfs(n, computers, childNode, visted)
return visted
Morty Proxy This is a proxified and sanitized view of the page, visit original site.