diff --git a/LeetCodeSharp.Tests/P589Tests.cs b/LeetCodeSharp.Tests/P589Tests.cs index 1ba123e..50748c5 100644 --- a/LeetCodeSharp.Tests/P589Tests.cs +++ b/LeetCodeSharp.Tests/P589Tests.cs @@ -1,4 +1,4 @@ -using LeetCodeSharp.Problems; +using LeetCodeSharp.Problems589; using LeetCodeSharp.Utils; namespace LeetCodeSharp.Tests; diff --git a/LeetCodeSharp/LeetCodeSharp.csproj b/LeetCodeSharp/LeetCodeSharp.csproj index e3bf522..b719c27 100644 --- a/LeetCodeSharp/LeetCodeSharp.csproj +++ b/LeetCodeSharp/LeetCodeSharp.csproj @@ -6,8 +6,4 @@ disable - - - - diff --git a/LeetCodeSharp/Problems/p589_n_ary_tree_preorder_traversal.cs b/LeetCodeSharp/Problems/Solution589.cs similarity index 93% rename from LeetCodeSharp/Problems/p589_n_ary_tree_preorder_traversal.cs rename to LeetCodeSharp/Problems/Solution589.cs index c1fe2f1..b4e066a 100644 --- a/LeetCodeSharp/Problems/p589_n_ary_tree_preorder_traversal.cs +++ b/LeetCodeSharp/Problems/Solution589.cs @@ -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 Preorder(Node root) { diff --git a/LeetCodeSharp/Problems/Solution590.cs b/LeetCodeSharp/Problems/Solution590.cs new file mode 100644 index 0000000..f33e21c --- /dev/null +++ b/LeetCodeSharp/Problems/Solution590.cs @@ -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 children; + + public Node() {} + + public Node(int _val) { + val = _val; + } + + public Node(int _val, IList _children) { + val = _val; + children = _children; + } +} +*/ + + public class Solution + { + public IList Postorder(Node root) + { + var dfs = new Dfs(); + + dfs.Search(root); + return dfs.Result; + } + + private class Dfs + { + public IList Result { get; } = new List(); + + 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 +} \ No newline at end of file