Skip to content

Commit

Permalink
update 815 java
Browse files Browse the repository at this point in the history
  • Loading branch information
yennanliu committed Dec 20, 2024
1 parent 65acaac commit f283417
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions leetcode_java/src/main/java/LeetCodeJava/BFS/BusRoutes.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public int numBusesToDestination_1(int[][] routes, int source, int target) {
}
HashMap<Integer, ArrayList<Integer>> adjList = new HashMap<>();
// Create a map from the bus stop to all the routes that include this stop.
/**
* NOTE !!!
*
* the `key` of map is the `route` index
*/
for (int r = 0; r < routes.length; r++) {
for (int stop : routes[r]) {
// Add all the routes that have this stop.
Expand Down Expand Up @@ -150,9 +155,7 @@ public int numBusesToDestination_1(int[][] routes, int source, int target) {
// V2
// IDEA : Breadth-First Search (BFS) with Routes as Nodes (test OK)
// https://leetcode.com/problems/bus-routes/editorial/

List<List<Integer>> adjList = new ArrayList();

// Iterate over each pair of routes and add an edge between them if there's a
// common stop.
void createGraph(int[][] routes) {
Expand Down

0 comments on commit f283417

Please sign in to comment.