This repository was archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
[2023-08-23] dohyun #143 #157
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """ | ||
|
|
||
| 풀이시간 | ||
| - 약 1시간 | ||
|
|
||
| 접근법 | ||
| - N = 200 -> 시간 복잡도 크게 고려하지 않아도 될 것 같음 (각 배열을 고려해 N^2 해도 충분) | ||
| - 모든 컴퓨터를 탐색하여 연결 정보를 찾아야 함 | ||
| - 그래프 탐색 알고리즘(DFS/BFS)을 사용해야겠다라고 판단 | ||
| - 제한 시간을 초과해서 답지를 봤습니다 .. ㅎ | ||
|
|
||
| 회고 | ||
| - DFS/BFS 유형은 매우 중요한데도 거의 손도 못대겠음 ㅠㅠ 해당 유형 문제 많이 풀어보기 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저는 처음에 BFS/DFS 감이 올랑말랑한데 막상 코드로 짜려니 막막했을 때 |
||
|
|
||
| """ | ||
|
|
||
| def solution(n, computers): | ||
| def dfs(node): | ||
| visited[node] = True # 현재 노드 방문 표시 | ||
| for neighbor in range(n): # 모든 노드 반복 | ||
| if computers[node][neighbor] == 1 and not visited[neighbor]: # 현재 노드와 연결되어 있고 and 방문하지 않은 노드 | ||
| dfs(neighbor) | ||
|
|
||
| visited = [False] * n | ||
| networks = 0 | ||
|
|
||
| for i in range(n): | ||
| if not visited[i]: # 방문하지 않은 노드에 대해 dfs 실시 | ||
| dfs(i) | ||
| networks += 1 | ||
|
|
||
| return networks | ||
|
|
||
| print(solution(n=3, computers=[[1, 1, 0], [1, 1, 0], [0, 0, 1]])) # 2 | ||
| print('----------') | ||
| print(solution(n=3, computers=[[1, 1, 0], [1, 1, 1], [0, 1, 1]])) # 1 | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
개인적으로 빙산 문제 풀이가 정말 좋았다고 생각해서 BFS/DFS 두 가지 방식으로 빙산 문제를 고민해보는게 좋을 것 같습니다!