[基本算法] Detect Cycle in Directed/Undirected Graph 有向图/无向图找环
2016-06-11
阅读 6 分钟
13.6kGiven n nodes labeled from 0 to n - 1 and a list of directed edges (each edge is a pair of nodes), write a function to check whether the graph contains a cycle. if edges = [0, 1], [1, 2], [0, 2]], it means 0 -> 1, 1 ->2, 0 -> 2. edges[i is parent, edgesi is child. For example: Given n = ...