You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: leetcode/medium/207_course_schedule.md
+24-25Lines changed: 24 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,39 +11,38 @@ The core of the problem is to find a cycle in the graph, as example 2 of the pro
11
11
12
12
We will need to create a graph, as it is not provided to us, it can be an adjacent list or a matrix, doesn't matter.
13
13
For any dfs, you will need a global visited and a local visited.
14
-
The global visited will tell us if we need to dfs starting at this node, this is to reduce run-time, else it will be O(N^N).
14
+
The global visited will tell us if we need to dfs starting at this node, this is to reduce run-time, else it will be O(N^2).
15
15
The local visited is for when we are traversing the graph via. dfs and looking for cycles.
16
16
17
-
I decided to use a dictionary to simplify the code, -1 will be used during the dfs, then after the dfs, changed into a 1, showing that its already visited and has no cycles. You can always use two separate visited sets but I find the code gets clunky.
0 commit comments