We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5706be7 commit 9899a6fCopy full SHA for 9899a6f
0207-course-schedule/0207-course-schedule.py
@@ -0,0 +1,27 @@
1
+class Solution:
2
+ def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool:
3
+ preMap = defaultdict(list)
4
+ visitSet = set()
5
+
6
+ for pre, cur in prerequisites:
7
+ preMap[cur].append(pre)
8
9
+ def dfs(crs):
10
+ if crs in visitSet:
11
+ return False
12
+ if preMap[crs] == []:
13
+ return True
14
15
+ visitSet.add(crs)
16
+ for pre in preMap[crs]:
17
+ if not dfs(pre):
18
19
+ visitSet.remove(crs)
20
+ preMap[crs] = []
21
22
23
+ for crs in range(numCourses):
24
+ if not dfs(crs):
25
26
27
0 commit comments