Last active
August 29, 2021 07:28
-
-
Save sdmcraft/3d154f711f1e754b5c6d3bdba6efd316 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
import java.util.ArrayList; | |
import java.util.List; | |
class Solution { | |
public boolean canFinish(int numTasks, int[][] prerequisites) { | |
List<Integer>[] adjacencyList = new ArrayList[numTasks]; | |
int[] prereqCount = new int[numTasks]; | |
for (int i = 0; i < prerequisites.length; i++) { | |
if(adjacencyList[prerequisites[i][1]] == null) { | |
adjacencyList[prerequisites[i][1]] = new ArrayList<>(); | |
} | |
adjacencyList[prerequisites[i][1]].add(prerequisites[i][0]); | |
prereqCount[prerequisites[i][0]]++; | |
} | |
... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment