| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- dfs
- nlp
- Python3
- 슬라이딩윈도우
- 알고리즘
- sql코테
- binary Tree
- 투포인터
- 릿코드
- two-pointer
- 코드업
- SQL
- heap
- 리트코드
- LeetCode
- GenerativeAI
- Greedy
- 파이썬
- codeup
- stratascratch
- GenAI
- graph
- Python
- array
- tree
- 니트코드
- 파이썬알고리즘
- BFS
- 생성형AI
- Stack
Archives
- Today
- Total
Tech for good
[Codepath/BFS, Graph] Count Connected Components 본문

def count_components(adjacency_dict):
# Write your code here
visited = set()
cnt = 0
def dfs(node):
visited.add(node)
for neighbor in adjacency_dict[node]:
if neighbor not in visited:
dfs(neighbor)
for node in adjacency_dict:
if node not in visited:
dfs(node)
cnt += 1
return cnt'IT > Computer Science' 카테고리의 다른 글
| [Leetcode/Array, Heap (Priority Queue)] 973. K Closest Points to Origin (0) | 2025.08.20 |
|---|---|
| [Leetcode/Array, Heap (Priority Queue) 1046. Last Stone Weight (0) | 2025.08.19 |
| [Codepath/BFS, Graph] Find Path (0) | 2025.08.12 |
| [Leetcode/DFS, BFS, Graph, Matrix] 200. Number of Islands (0) | 2025.08.09 |
| [Leetcode/DFS, BFS, Graph] 1971. Find if Path Exists in Graph (0) | 2025.08.08 |