简历:The Google Resume: How to Prepare for a Career and Land a Job at Apple, Microsoft, Google, or any Top Tech Company
算法学习书籍:Introduction to Algorithms
编程珠玑:Programming Pearls (2nd Edition)
C++ 学习:The C++ Programming Language, 4th Edition
经典操作系统书籍,龙书:Operating System Concepts
创业:The Start-up of You: Adapt to the Future, Invest in Yourself, and Transform Your Career
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 from 0 to N - 1, where N is the total nodes in the graph.
We use #
as a separator for each node, and ,
as a separator for each neighbor of the node.
As an example, consider the serialized graph
{1,2#2#2}
.
The graph has a total of three nodes, and therefore contains three parts as separated by
#
.- Connect node 0 to both nodes
1
and2
. - Connect node 1 to node
2
. - Connect node 2 to node
2
(itself), thus forming a self-cycle.
Visually, the graph looks like the following:
1 / \ / \ 0 --- 2 / \ \_/
这题不难,就是很烦人,主要是要搞清楚新建立的结点,指针,存放在HASHMAP和QUEUE里的分别是什么,对应清楚就好。HASHMAP用来MARK已经VSITED的NODE,QUEUE用来做BFS来CLONE GRAPH。
No comments:
Post a Comment