美文网首页
127. Topological Sorting

127. Topological Sorting

作者: 鸭蛋蛋_8441 | 来源:发表于2019-05-30 07:08 被阅读0次

Description

Given an directed graph, a topological order of the graph nodes is defined as follow:

For each directed edge A -> B in graph, A must before B in the order list.

The first node in the order can be any node in the graph with no nodes direct to it.

Find any topological order for the given graph.

You can assume that there is at least one topological order in the graph.

Clarification

Learn more about representation of graphs

Example

For graph as follow:

The topological order can be:

[0, 1, 2, 3, 4, 5]

[0, 2, 3, 1, 5, 4]

...

Challenge

Can you do it in both BFS and DFS?

思路:

套路很简单,记住就可以了,就是一个简单的拓扑排序

代码:

相关文章

网友评论

      本文标题:127. Topological Sorting

      本文链接:https://www.haomeiwen.com/subject/wzvptctx.html