You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
LintCode Copyright Geeks for Geeks Depth First Search Breadth First Search
45
48
49
+
*/
50
+
51
+
/**
52
+
46
53
Thoughts:
47
54
First idea is Breadth First Search.
48
-
1. Find the node which has no parent node: this will be the beginning node. Use a HashMap to map all nodes with children, and whatever not in that map, is a root option.
55
+
1. Find the node which has no parent node: this will be the beginning node.
56
+
Use a HashMap to map all nodes with children, and whatever not in that map, is a root option.
49
57
2. Starting from this node, put all nodes in the queue (breadth-first)
50
58
3. process each node in the queue: add to array list
51
59
52
60
53
61
Note: All all possible root node (whatever not added into the map) because there could be multiple heads : (. Really need to ask about this if not sure.
54
62
55
-
*/
56
-
63
+
*/
57
64
/**
58
65
* Definition for Directed graph.
59
66
* class DirectedGraphNode {
@@ -73,21 +80,21 @@ public ArrayList<DirectedGraphNode> topSort(ArrayList<DirectedGraphNode> graph)
0 commit comments