797. All Paths From Source to Target
class Solution:
def allPathsSourceTarget(self, graph: List[List[int]]) -> List[List[int]]:
answer = []
N = len(graph)
q = collections.deque([[0, [0]]])
while q:
curr, route = q.popleft()
if curr == N-1:
answer.append(route)
else:
for nei in graph[curr]:
q.append([nei, route + [nei]])
return answer