Graph
共 4 篇文章
Leetcode - Alien Dictionary
There is a new alien language which uses the latin alphabet. However, the order among letters are unknown to you. You receive a list of words from the dictionary, where words are sorted lexicographically by the rules of this new language. Derive the order of letters in this language. For example, G…
2015-09-04 11:58 · Graph · Topological Sort
Leetcode - Course Schedule II
[分析] 在题I代码基础上增加记录拓扑遍历顺序即可。 [code="java"] public class Solution { public int[] findOrder(int numCourses, int[][] prerequisites) { if (prerequisites == null) return new int[0]; int[] order = new int[numCourses]; List> graph = new ArrayList>(); int[] indegree = new int[numCourses]; for (int i = 0; i <…
2015-09-03 21:05 · Graph
Leetcode - Course Schedule
[分析] 拓扑排序的经典应用。review时发现自己搞反了课程直接的依赖关系,但却真切地被Accept, 图上画了画,发现搞反后若输出排序结果就是和原来相反,但不影响本题的正确性。 网上搜了搜逆拓扑,发现其是有可用之处的,参见下面这篇博文: [url]http://blog.csdn.net/guodongxiaren/article/details/37988833[/url] 另一篇博文提出拓扑排序是所有节点dfs的逆后序,也就是每个节点任务完成的时间的逆序排序 ,这个洞见也挺有意思的[url]https://m.oschina.net/blog/419291[/url] [code="…
2015-09-03 20:21 · Graph
Leetcode - Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected graph serialization: Nodes are labeled uniquely. We use # as a separator for each node, and , as a separator for node label and each neighbor of the node. As an example, consider the seri…
2015-06-29 21:59 · Breadth-first Search · Graph