Last active
January 2, 2022 17:02
-
-
Save press0/2262ebdcd117dde20455aa7149bfb933 to your computer and use it in GitHub Desktop.
This file contains 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
def dfs(adj_list, start, target, path, visited=set()): | |
path.append(start) | |
visited.add(start) | |
if start == target: | |
return path | |
for neighbour in adj_list[start]: | |
if neighbour not in visited: | |
result = dfs(adj_list, neighbour, target, path, visited) | |
if result is not None: | |
return result | |
path.pop() // <-- indentation matters | |
//path.pop() | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment