20240219 Finished
This commit is contained in:
parent
a0ed8ba7da
commit
9978017d28
|
@ -1,4 +1,4 @@
|
|||
using LeetCodeSharp.Problems;
|
||||
using LeetCodeSharp.Problems589;
|
||||
using LeetCodeSharp.Utils;
|
||||
|
||||
namespace LeetCodeSharp.Tests;
|
||||
|
|
|
@ -6,8 +6,4 @@
|
|||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Problems\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
using LeetCodeSharp.Utils;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LeetCodeSharp.Problems
|
||||
namespace LeetCodeSharp.Problems589
|
||||
{
|
||||
|
||||
// Submission codes start here
|
||||
|
@ -30,7 +30,7 @@ public class Node {
|
|||
}
|
||||
*/
|
||||
|
||||
public partial class Solution
|
||||
public class Solution
|
||||
{
|
||||
public IList<int> Preorder(Node root)
|
||||
{
|
61
LeetCodeSharp/Problems/Solution590.cs
Normal file
61
LeetCodeSharp/Problems/Solution590.cs
Normal 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
|
||||
}
|
Loading…
Reference in New Issue
Block a user