Submission Detail

52 / 52 test cases passed.
Status:

Accepted

Runtime: 206 ms
Memory Usage: 16.4 MB
Submitted: 0 minutes ago
loading
Runtime Error Message:
Last executed input:
Input:
Output:
Expected:

Accepted Solutions Runtime Distribution

50
100
150
200
250
300
350
400
450
500
550
2
4
6
8
python
You are here!
Your runtime beats 8.71 % of python submissions.
Runtime (ms)
Distribution (%)

50
100
150
200
250
300
350
400
450
500
550
2.5
5.0
7.5
Zoom area by dragging across this chart

Accepted Solutions Memory Distribution

14500
14750
15000
15250
15500
15750
16000
16250
16500
16750
2
4
6
8
10
12
python
You are here!
Your memory usage beats 26.37 % of python submissions.
Memory (KB)
Distribution (%)

14500
14750
15000
15250
15500
15750
16000
16250
16500
16750
5
10
Zoom area by dragging across this chart

Invite friends to challenge Course Schedule


Submitted Code: 0 minutes ago

Language: python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Solution(object):
def canFinish(self, numCourses, prerequisites):
"""
:type numCourses: int
:type prerequisites: List[List[int]]
:rtype: bool
"""
if (len(prerequisites) == 1):
return True
def detectCycle(nodes, visited, stack):
for n in nodes[stack[0]]:
if (n in visited and n in stack):
return True
elif (n not in visited):
stack.insert(0,n)
visited.append(n)
cycle = detectCycle(nodes,visited,stack)
if (cycle == True):
return True
stack.pop(0)
return False
nodes = {}
for p in prerequisites:
if (p[1] not in nodes):
nodes[p[1]] = [p[0]]
else:
nodes[p[1]].append(p[0])
for i in range(0,numCourses):
if (i not in nodes):
nodes[i] = []
visited = []
stack = []
for i in range(0,numCourses):
if i not in visited:
stack = []
stack.insert(0,i)
visited.append(i)
cycle = detectCycle(nodes,visited,stack)
if (cycle == True):
return False
return True
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX