@mohamed-ebrahim great idea
Interviewer won't care about OJ. Besides, using Node as the key won't hurt. It's a more general method.
The hash map has two functionalities:
if(mp.find(node) != mp.end())
you should not return NULL, but return the vertex in the new graph, that is hash_map(vertex)
wonderful!!!! without recursive, we can use queue, however performance has declined!
I think the input from OJ is problematic, because some correct solution can't be accepted in this way. Please take a look at https://leetcode.com/discuss/107760/believe-undirected-graph-neighbor-should-always-contain-other
No one has replied
@ericakimnh It looks like BSF, but he's actually popping from the end of the list, not the head, which makes it DFS. At first I thought it BSF too :)
I figure it out : marks[n->label] is the copy of n, they are not the same address.
@Lazysheep.ma Isn't that the only difference between BFS and DFS?
It's exactly a DFS copy, and comparing with BFS version, it looks concise.
Here are my BFS copy.
this should be corrected. It is confusing people.
Well, now the paragraph about OJ's undirected graph serialization is not useful at all to solve this question.
@ArchiiiTech I agree. This problem itself is actually a directed graph. All edges in the graph are unidirectional.
@lijinglun, visited[x->label] = x; // i think this step is not necessary
Disabled Categories are greyed out
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.