Day6. Namespace style

This commit is contained in:
Electrominch
2022-10-07 16:36:27 +03:00
parent 62104da8f1
commit 5cae083979
51 changed files with 589 additions and 202 deletions

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>_589._N_ary_Tree_Preorder_Traversal</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,21 @@
namespace _589._N_ary_Tree_Preorder_Traversal;
// Definition for a Node.
public class Node
{
public int val;
public IList<Node>? children;
public Node() { }
public Node(int _val)
{
val = _val;
}
public Node(int _val, IList<Node> _children)
{
val = _val;
children = _children;
}
}

View File

@@ -0,0 +1,9 @@
namespace _589._N_ary_Tree_Preorder_Traversal;
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello, World!");
}
}

View File

@@ -0,0 +1,22 @@
namespace _589._N_ary_Tree_Preorder_Traversal;
public class Solution
{
public IList<int> Preorder(Node root)
{
List<int> list = new List<int>();
RecursiveTraversal(list, root);
return list;
}
private void RecursiveTraversal(List<int> output, Node cur)
{
if (cur == null)
return;
output.Add(cur.val);
if (cur.children == null)
return;
foreach (var child in cur.children)
RecursiveTraversal(output, child);
}
}