This file contains hidden or 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
class Solution { | |
public List<Integer> eventualSafeNodes(int[][] graph) { | |
int v = graph.length; | |
int[] outdegreeCount = new int[v]; | |
List<List<Integer>> indegree = new ArrayList<>(); | |
for(int i = 0; i < v; i++){ |
This file contains hidden or 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
class Solution { | |
public boolean canFinish(int numCourses, int[][] prerequisites) { | |
List<List<Integer>> adj = new ArrayList<>(); | |
for(int i = 0; i < numCourses; i++){ | |
adj.add(new ArrayList<>()); | |
} | |
int[] indegreeCount = new int[numCourses]; |
This file contains hidden or 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
class Solution { | |
private boolean dfs(int node, int color, int[] isColored, int[][] graph){ | |
isColored[node] = color; | |
for(int neighbour : graph[node]){ | |
if(isColored[neighbour] == -1){ | |
if(!dfs(neighbour, 1 - color, isColored, graph)){ |