LeetCode - 207. Course Schedule
207. Course Schedule
Problem's Link
----------------------------------------------------------------------------
Mean:
给定一个有向图,判断是否存在top_sort序列.
analyse:
转换为:判断是否存在环.
若存在环,肯定不能找到top_sort序列.
判环的方式有很多:SPFA,top_sort,BFS,DFS...随便选一种就行.
Time complexity: O(N)
view code
我的代码:
)
) ;;;
}
/*
*/
下面是discuss区的代码,看了一下,感觉还有很多可以优化的地方,我在代码中注释出来了.
代码1:
for(auto it = matrix[i].begin(); it != matrix[i].end(); ++ it)
-- d[*it];
}
return true;
}
代码2:
;
);
for (auto neighbors : graph)
for (int neigh : neighbors)
degrees[neigh]++;
return degrees;
}
};
LeetCode - 207. Course Schedule的更多相关文章
- Java for LeetCode 207 Course Schedule【Medium】
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- LN : leetcode 207 Course Schedule
lc 207 Course Schedule 207 Course Schedule There are a total of n courses you have to take, labeled ...
- [LeetCode] 207. Course Schedule 课程安排
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- [LeetCode] 207. Course Schedule 课程清单
There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prereq ...
- (medium)LeetCode 207.Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
- LeetCode 207. Course Schedule(拓扑排序)
题目 There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have p ...
- [LeetCode] 207. Course Schedule 课程表
题目: 分析: 这是一道典型的拓扑排序问题.那么何为拓扑排序? 拓扑排序: 有三件事情A,B,C要完成,A随时可以完成,但B和C只有A完成之后才可完成,那么拓扑排序可以为A>B>C或A&g ...
- [leetcode]207. Course Schedule课程表
在一个有向图中,每次找到一个没有前驱节点的节点(也就是入度为0的节点),然后把它指向其他节点的边都去掉,重复这个过程(BFS),直到所有节点已被找到,或者没有符合条件的节点(如果图中有环存在). /* ...
- Java for LeetCode 210 Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...
随机推荐
- 再谈扩展方法,从string.IsNullOrEmpty()说起
string.IsNullOrEmpty()这个方法算得上是.net中使用频率最高的方法之一.此方法是string的一个静态方法,类似的静态方法在string这个类中还有很多.那么这样的方法作为静态方 ...
- dojo/dom-construct.toDom方法学习笔记
toDom方法用来将html标签字符串转化成DOM节点.1.7之后toDom方法被分配到了dom-construct模块. require(["dojo/dom-construct" ...
- IE浏览器不能自动显示PDF文件的解决办法
今天更新了Adobe的PDF Reader,更新后发现在网页上无法预览PDF文件了,点击PDF的连接,浏览器就会提示下载或者打开,感觉很不爽,经过一番百度,找到了解决办法,在这里分享一下. 打开IE浏 ...
- 浅析Windows安全相关的一些概念
Session 我们平常所说的Session是指一次终端登录, 这里的终端登录是指要有自己的显示器和鼠标键盘等, 它包括本地登录和远程登录.在XP时代每次终端登录才会创建一个Session,但是在Vi ...
- Stealth视频教程学习笔记(第二章)
Stealth视频教程学习笔记(第二章) 本文是对Unity官方视频教程Stealth的学习笔记.在此之前,本人整理了Stealth视频的英文字幕,并放到了优酷上.本文将分别对各个视频进行学习总结,提 ...
- Android 数据传递(二)Activity与fragment之间的通信
在网上找到了一篇总结的非常好的文章,我这里就贴出他的博文地址.自己就不再写这个方面的总结了. Activity与Fragment通信(99%)完美解决方案
- swift 项目 oc 和 swift 混用,文件相互引用
创建swift工程后,如果后面想新建 oc 文件,这时会生成一个 AppName-Bridging-Header.h文件 一,在swift 文件中 1> 引用swift 文件 什么都不需要操作 ...
- C#学习系列-.NET体系结构
.NET框架概述 .NET 框架为.NET应用程序运行提供虚拟机环境,为.NET应用程序提供编译.运行.内存管理.垃圾回收.安全等服务. .NET框架组成部分 1.公共语言运行时(Common L ...
- 每天一个linux命令(14):head 命令
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...
- Change Git Default Editor in Windows
On 32 bit Win OS: git config --global core.editor "'C:/Program Files/Notepad++/notepad++.exe' - ...