source
equals target
, return 0.adjList
to store bus stops as keys and lists of route indices as values.q
and a set vis
to track visited routes.q
and mark them in vis
.q
is empty:
a. Pop a route from q
.
b. For each stop in the route:
i. If stop equals target
, return bus count.
ii. For each route in adjList
with this stop, add unvisited routes to q
and mark visited.target
, return -1.