Skip to content

Instantly share code, notes, and snippets.

@sdmcraft
Last active August 29, 2021 07:28
Show Gist options
  • Select an option

  • Save sdmcraft/3d154f711f1e754b5c6d3bdba6efd316 to your computer and use it in GitHub Desktop.

Select an option

Save sdmcraft/3d154f711f1e754b5c6d3bdba6efd316 to your computer and use it in GitHub Desktop.

Revisions

  1. sdmcraft renamed this gist Aug 29, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. sdmcraft renamed this gist Aug 27, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. sdmcraft created this gist Aug 27, 2021.
    16 changes: 16 additions & 0 deletions course
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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]]++;
    }
    ...
    }
    }