Movatterモバイル変換


[0]ホーム

URL:


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

Commit117a1d9

Browse files
authored
Merge pull requestneetcode-gh#1002 from agnihotriketan/patch-6
C# Create 133-Clone-Graph.cs
2 parents603087c +47cb370 commit117a1d9

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

‎csharp/133-Clone-Graph.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
// Definition for a Node.
3+
public class Node {
4+
public int val;
5+
public IList<Node> neighbors;
6+
7+
public Node() {
8+
val = 0;
9+
neighbors = new List<Node>();
10+
}
11+
12+
public Node(int _val) {
13+
val = _val;
14+
neighbors = new List<Node>();
15+
}
16+
17+
public Node(int _val, List<Node> _neighbors) {
18+
val = _val;
19+
neighbors = _neighbors;
20+
}
21+
}
22+
*/
23+
24+
publicclassSolution{
25+
26+
Dictionary<Node,Node>map=newDictionary<Node,Node>();
27+
28+
publicNodeCloneGraph(Nodenode){
29+
if(node==null)returnnull;
30+
if(!map.ContainsKey(node))
31+
{
32+
map.Add(node,newNode(node.val));
33+
foreach(varninnode.neighbors)
34+
{
35+
map[node].neighbors.Add(CloneGraph(n));
36+
}
37+
}
38+
39+
returnmap[node];
40+
}
41+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp