1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| List<Integer>[] buildGraph(int numCourses, int[][] prerequisites) { List<Integer>[] graph = new LinkedList[numCourses]; for (int i = 0; i < numCourses; i++) { graph[i] = new LinkedList<>(); } for (int[] edge : prerequisites) { int from = edge[1]; int to = edge[0]; graph[from].add(to); } return graph; }
|