20240219 Finished

This commit is contained in:
jackfiled 2024-02-19 10:56:10 +08:00
parent a0ed8ba7da
commit 9978017d28
4 changed files with 64 additions and 7 deletions

View File

@ -1,4 +1,4 @@
using LeetCodeSharp.Problems; using LeetCodeSharp.Problems589;
using LeetCodeSharp.Utils; using LeetCodeSharp.Utils;
namespace LeetCodeSharp.Tests; namespace LeetCodeSharp.Tests;

View File

@ -6,8 +6,4 @@
<Nullable>disable</Nullable> <Nullable>disable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Folder Include="Problems\" />
</ItemGroup>
</Project> </Project>

View File

@ -6,7 +6,7 @@
using LeetCodeSharp.Utils; using LeetCodeSharp.Utils;
using System.Collections.Generic; using System.Collections.Generic;
namespace LeetCodeSharp.Problems namespace LeetCodeSharp.Problems589
{ {
// Submission codes start here // Submission codes start here
@ -30,7 +30,7 @@ public class Node {
} }
*/ */
public partial class Solution public class Solution
{ {
public IList<int> Preorder(Node root) public IList<int> Preorder(Node root)
{ {

View File

@ -0,0 +1,61 @@
/**
* [N-ary Tree Postorder Traversal] 590
*/
using System.Collections.Generic;
using LeetCodeSharp.Utils;
namespace LeetCodeSharp.Problems590
{
// Submission codes start here
/*
// 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;
}
}
*/
public class Solution
{
public IList<int> Postorder(Node root)
{
var dfs = new Dfs();
dfs.Search(root);
return dfs.Result;
}
private class Dfs
{
public IList<int> Result { get; } = new List<int>();
public void Search(Node node)
{
if (node == null) return;
foreach (var child in node.children)
{
Search(child);
}
Result.Add(node.val);
}
}
}
// Submission codes end here
}