MCPcopy Create free account
hub / github.com/austingebauer/go-leetcode / hasCycleDFS

Function hasCycleDFS

course_schedule_207/solution.go:85–103  ·  view source on GitHub ↗
(adjList map[int][]int, colors []int, course int)

Source from the content-addressed store, hash-verified

83}
84
85func hasCycleDFS(adjList map[int][]int, colors []int, course int) bool {
86 // if this node is an ancestor of the DFS path taken, there is a cycle
87 if colors[course] == 1 {
88 return true
89 }
90
91 // mark the course as seen
92 colors[course] = 1
93
94 cycles := false
95 for _, prereq := range adjList[course] {
96 cycles = cycles || hasCycleDFS(adjList, colors, prereq)
97 }
98
99 // unmark the course as seen on way back up the call stack
100 colors[course] = 0
101
102 return cycles
103}

Callers 1

canFinishDFSFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected