mirror of
https://github.com/yangshun/tech-interview-handbook.git
synced 2026-02-03 10:34:43 +08:00
Fix small issue with bfs algorithm (#141)
Algorithm performed a dfs rather than bfs because of the queue.pop() error on line 78. Updated to queue.popleft()
This commit is contained in:
@@ -75,7 +75,7 @@ def bfs(matrix):
|
||||
def traverse(i, j):
|
||||
queue = deque([(i, j)])
|
||||
while queue:
|
||||
curr_i, curr_j = queue.pop()
|
||||
curr_i, curr_j = queue.popleft()
|
||||
if (curr_i, curr_j) not in visited:
|
||||
visited.add((curr_i, curr_j))
|
||||
# Traverse neighbors.
|
||||
|
||||
Reference in New Issue
Block a user