Skip to content

Instantly share code, notes, and snippets.

@sdmcraft
Last active August 29, 2021 07:21
Show Gist options
  • Save sdmcraft/9c6d505b2960c4991605278ab5c5cfef to your computer and use it in GitHub Desktop.
Save sdmcraft/9c6d505b2960c4991605278ab5c5cfef to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.List;
class Solution {
public boolean canFinish(int numTasks, int[][] prerequisites) {
...
boolean proceed = true;
while (proceed) {
proceed = false;
for (int i = 0; i < numTasks; i++) {
if (prereqCount[i] == 0 && adjacencyList[i] != null) {
for (int task : adjacencyList[i]) {
prereqCount[task]--;
}
adjacencyList[i] = null;
}
}
for (int i = 0; i < numTasks; i++) {
if (prereqCount[i] == 0 && adjacencyList[i] != null) {
proceed = true;
break;
}
}
}
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment