Skip to content

Commit fdc90b5

Browse files
committed
Runtime: 4426 ms (Top 5.00%) | Memory: 313.2 MB (Top 8.29%)
1 parent 1c72856 commit fdc90b5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# Runtime: 4426 ms (Top 5.00%) | Memory: 313.2 MB (Top 8.29%)
2+
13
class Solution:
24
def validPath(self, n: int, edges: List[List[int]], start: int, end: int) -> bool:
35
graph = self.buildGraph(edges)
46
return self.hasPath(graph, start, end, set())
5-
6-
# function to convert list of edges to adjacency list graph
7+
8+
# function to convert list of edges to adjacency list graph
79
def buildGraph(self, edges):
810
graph = {}
911
for edge in edges:
@@ -13,9 +15,9 @@ def buildGraph(self, edges):
1315
if b not in graph:
1416
graph[b] = []
1517
graph[a].append(b)
16-
graph[b].append(a)
18+
graph[b].append(a)
1719
return graph
18-
20+
1921
def hasPath(self, graph, src, dst, visited):
2022
if src == dst:
2123
return True
@@ -25,4 +27,4 @@ def hasPath(self, graph, src, dst, visited):
2527
for neighbour in graph[src]:
2628
if self.hasPath(graph, neighbour, dst, visited) == True:
2729
return True
28-
return False
30+
return False

0 commit comments

Comments
 (0)