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

from collections import deque, defaultdict
def has_path(adjacency_dict, start, destination):
# Write your code here
if start == destination:
return True
graph = defaultdict(list, adjacency_dict)
q = deque([start])
visited = set([start])
while q:
curr = q.popleft()
if curr == destination:
return True
for neighbor in graph[curr]:
if neighbor not in visited:
visited.add(neighbor)
q.append(neighbor)
return False'IT > Computer Science' 카테고리의 다른 글
| [Leetcode/Array, Heap (Priority Queue) 1046. Last Stone Weight (0) | 2025.08.19 |
|---|---|
| [Codepath/BFS, Graph] Count Connected Components (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 |
| [Leetcode/Array, Hash Table, Graph] 997. Find the Town Judge (0) | 2025.08.08 |