有些算法,自己觉得也就是那么回事,特别简单,但是想清楚每个细节怎么做,有什么小技巧,把它快速的实现出来,并不是那么容易。从想法到实现,总是有差距的。
经典问题:Course Schedule
LeetCode 207. Course Schedule
https://leetcode.com/problems/course-schedule/description/
There are a total of n courses you have to take, labeled from 0 to n-1.
Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pair: [0,1]
Given the total number of courses and a list of prerequisite pairs, is it possible for you to finish all courses?
Example 1:
|
|
Example 2:
|
|
BFS
|
|
C++实现
|
|
DFS
TODO..