Skip to content

Instantly share code, notes, and snippets.

@bruceoutdoors
Created June 24, 2018 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bruceoutdoors/7b2da1c7af0c9f7797eb61787e515908 to your computer and use it in GitHub Desktop.
Save bruceoutdoors/7b2da1c7af0c9f7797eb61787e515908 to your computer and use it in GitHub Desktop.
public class Solution {
IList<IList<int>> graph;
bool[] marked;
public bool CanVisitAllRooms(IList<IList<int>> rooms) {
graph = rooms;
marked = new bool[rooms.Count];
dfs(0);
foreach (bool b in marked) {
if (!b) return false;
}
return true;
}
private void dfs(int v) {
marked[v] = true;
foreach (int w in graph[v]) {
if (!marked[w]) {
dfs(w);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment