Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1460701

Browse files
author
Shuo
authored
Merge pull request #417 from openset/develop
Update: description
2 parents b2cfbe0 + d858ac7 commit 1460701

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

‎problems/clone-graph/README.md

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,41 +11,35 @@
1111

1212
## 133. Clone Graph (Medium)
1313

14-
<p>Given the head of a&nbsp;graph, return a deep copy (clone) of the graph. Each node in the graph contains a <code>label</code>&nbsp;(<code>int</code>) and a list (<code>List[UndirectedGraphNode]</code>) of its <code>neighbors</code>. There is an edge between the given node and each of the nodes in its neighbors.</p>
15-
16-
<div><br />
17-
<b>OJ&#39;s undirected graph serialization (so you can understand error output):</b>
18-
19-
<p>Nodes are labeled uniquely.</p>
20-
We use <code>#</code> as a separator for each node, and <code>,</code> as a separator for node label and each neighbor of the node.
14+
<p>Given&nbsp;a reference of a node in a&nbsp;<strong><a href="https://en.wikipedia.org/wiki/Connectivity_(graph_theory)#Connected_graph" target="_blank">connected</a></strong>&nbsp;undirected graph, return a <a href="https://en.wikipedia.org/wiki/Object_copying#Deep_copy" target="_blank"><strong>deep copy</strong></a> (clone) of the graph. Each node in the graph contains a val (<code>int</code>) and a list (<code>List[Node]</code>) of its neighbors.</p>
2115

2216
<p>&nbsp;</p>
2317

24-
<p>As an example, consider the serialized graph <code><fontcolor="red">{<fontcolor="black">0</font>,1,2#</font><fontcolor="blue"><fontcolor="black">1</font>,2#</font><fontcolor="green"><fontcolor="black">2</font>,2}</font></code>.</p>
18+
<p><strong>Example:</strong></p>
2519

26-
<p>The graph has a total of three nodes, and therefore contains three parts as separated by <code>#</code>.</p>
20+
<p><imgalt=""src="https://assets.leetcode.com/uploads/2019/02/19/113_sample.png"style="width: 200px; height: 149px;" /></p>
2721

28-
<ol>
29-
<li>First node is labeled as <code><font color="black">0</font></code>. Connect node <code><font color="black">0</font></code> to both nodes <code><font color="red">1</font></code> and <code><font color="red">2</font></code>.</li>
30-
<li>Second node is labeled as <code><font color="black">1</font></code>. Connect node <code><font color="black">1</font></code> to node <code><font color="blue">2</font></code>.</li>
31-
<li>Third node is labeled as <code><font color="black">2</font></code>. Connect node <code><font color="black">2</font></code> to node <code><font color="green">2</font></code> (itself), thus forming a self-cycle.</li>
32-
</ol>
22+
<pre>
23+
<strong>Input:
24+
</strong>{&quot;$id&quot;:&quot;1&quot;,&quot;neighbors&quot;:[{&quot;$id&quot;:&quot;2&quot;,&quot;neighbors&quot;:[{&quot;$ref&quot;:&quot;1&quot;},{&quot;$id&quot;:&quot;3&quot;,&quot;neighbors&quot;:[{&quot;$ref&quot;:&quot;2&quot;},{&quot;$id&quot;:&quot;4&quot;,&quot;neighbors&quot;:[{&quot;$ref&quot;:&quot;3&quot;},{&quot;$ref&quot;:&quot;1&quot;}],&quot;val&quot;:4}],&quot;val&quot;:3}],&quot;val&quot;:2},{&quot;$ref&quot;:&quot;4&quot;}],&quot;val&quot;:1}
25+
26+
<strong>Explanation:</strong>
27+
Node 1&#39;s value is 1, and it has two neighbors: Node 2 and 4.
28+
Node 2&#39;s value is 2, and it has two neighbors: Node 1 and 3.
29+
Node 3&#39;s value is 3, and it has two neighbors: Node 2 and 4.
30+
Node 4&#39;s value is 4, and it has two neighbors: Node 1 and 3.
31+
</pre>
3332

3433
<p>&nbsp;</p>
3534

36-
<p>Visually, the graph looks like the following:</p>
35+
<p><strong>Note:</strong></p>
3736

38-
<pre>
39-
1
40-
/ \
41-
/ \
42-
0 --- 2
43-
/ \
44-
\_/
45-
</pre>
46-
47-
<p><strong>Note</strong>: The information about the tree serialization is only meant so that you can understand error output if you get a wrong answer. You don&#39;t need to understand the serialization to solve the problem.</p>
48-
</div>
37+
<ol>
38+
<li>The number of nodes will be between 1 and 100.</li>
39+
<li>The undirected&nbsp;graph is a <a href="https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)#Simple_graph" target="_blank">simple graph</a>,&nbsp;which means no repeated edges and no self-loops in the graph.</li>
40+
<li>Since the graph is undirected, if node <em>p</em>&nbsp;has node <em>q</em>&nbsp;as&nbsp;neighbor, then node <em>q</em>&nbsp;must have node <em>p</em>&nbsp;as neighbor too.</li>
41+
<li>You must return the <strong>copy of the given node</strong> as a reference to the cloned graph.</li>
42+
</ol>
4943

5044
### Related Topics
5145
[[Depth-first Search](https://github.com/openset/leetcode/tree/master/tag/depth-first-search/README.md)]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /