Skip to content

Commit 9855a42

Browse files
committed
Add solution #590
1 parent 9f6b18f commit 9855a42

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@
457457
583|[Delete Operation for Two Strings](./0583-delete-operation-for-two-strings.js)|Medium|
458458
587|[Erect the Fence](./0587-erect-the-fence.js)|Hard|
459459
589|[N-ary Tree Preorder Traversal](./0589-n-ary-tree-preorder-traversal.js)|Easy|
460+
590|[N-ary Tree Postorder Traversal](./0590-n-ary-tree-postorder-traversal.js)|Easy|
460461
594|[Longest Harmonious Subsequence](./0594-longest-harmonious-subsequence.js)|Easy|
461462
599|[Minimum Index Sum of Two Lists](./0599-minimum-index-sum-of-two-lists.js)|Easy|
462463
605|[Can Place Flowers](./0605-can-place-flowers.js)|Easy|
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* 590. N-ary Tree Postorder Traversal
3+
* https://leetcode.com/problems/n-ary-tree-postorder-traversal/
4+
* Difficulty: Easy
5+
*
6+
* Given the root of an n-ary tree, return the postorder traversal of its nodes' values.
7+
*
8+
* Nary-Tree input serialization is represented in their level order traversal. Each group
9+
* of children is separated by the null value (See examples)
10+
*/
11+
12+
/**
13+
* // Definition for a _Node.
14+
* function _Node(val,children) {
15+
* this.val = val;
16+
* this.children = children;
17+
* };
18+
*/
19+
20+
/**
21+
* @param {_Node|null} root
22+
* @return {number[]}
23+
*/
24+
var postorder = function(root) {
25+
const result = [];
26+
traverse(root);
27+
return result;
28+
29+
function traverse(node) {
30+
if (!node) return;
31+
node.children.forEach(child => traverse(child));
32+
result.push(node.val);
33+
}
34+
};

0 commit comments

Comments
 (0)