207. Course Schedule

You are given an array prerequisites where prerequisites[i] = [ai, bi] indicates that you must take course bi first if you want to take course ai.

[a, b] => b first : b -> a

[1] first, [0] is node, so cal indegree in [0]

use topology sort

cal indegree, if indegree == 0 put into queue (means prerequs..), Then BFS

indegree 0 means it's a start point

for loop , look up which course first ([1]) need start point (means start from this

new version

time: O(V+E)

space: O(n), n is numCourses

Last updated

Was this helpful?