From 73b87e0bfa8af4e0c31e0d64306a5ce1c5c77ab9 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Mon, 26 Aug 2024 21:56:20 +0530 Subject: [PATCH] Create 590. N-ary Tree Postorder Traversal --- 590. N-ary Tree Postorder Traversal | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 590. N-ary Tree Postorder Traversal diff --git a/590. N-ary Tree Postorder Traversal b/590. N-ary Tree Postorder Traversal new file mode 100644 index 0000000..e6c5029 --- /dev/null +++ b/590. N-ary Tree Postorder Traversal @@ -0,0 +1,22 @@ +class Solution { +public: + vector ans; + + void solve(Node* root) { + if (root == 0) { + return; + } + + for (const auto& node : root->children) { + solve(node); + } + + ans.push_back(root->val); + return; + } + + vector postorder(Node* root) { + solve(root); + return ans; + } +};