## 知之可否

Be yourself; everyone else is already taken.​

# 拓扑排序：课程表Course Schedule2

https://leetcode.com/problems/course-schedule-ii/

class Solution {
public:
vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) {

vector<int> res;
vector<int> inDgree(numCourses,0);

int len = prerequisites.size();
for (int i = 0; i < len; i++){
pair<int, int> p = prerequisites[i];

//自环
if (p.first == p.second)
return res;

//平行边
inDgree[p.first]++;
}
}

queue<int> Q;

for (int i=0; i < numCourses; i++){
if (inDgree[i] == 0)
Q.push(i);
}

while (!Q.empty()){
int front = Q.front();
Q.pop();

res.push_back(front);

inDgree[i]--;
if (inDgree[i] == 0){
Q.push(i);
}
}
}

if (res.size() == numCourses){
return res;
}
else{
return vector<int>();
}

}

};

#### LeetCode207课程表

2018-03-11 12:05:33

#### LintCode-615: Course Schedule and Course Schedule II 拓扑排序经典题

2018-05-31 12:47:58

#### 615. Course Schedule-课程表（拓扑排序）

2018-04-10 10:01:40

#### LintCode 615. Course Schedule

2018-02-15 18:18:44

#### 拓扑排序：课程表Course Schedule

2016-05-31 16:28:56

#### 课程表-LintCode

2017-11-09 11:20:28

#### 拓扑排序 ---排课表----数据结构

2010年06月13日 414KB 下载

#### LintCode_安排课程

2017-08-21 21:14:07

#### lintcode(616)安排课程

2017-05-18 09:59:26

#### 拓扑排序（C语言实现）

2016-12-14 17:31:04