File tree 2 files changed +35
-0
lines changed
2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 457
457
583|[ Delete Operation for Two Strings] ( ./0583-delete-operation-for-two-strings.js ) |Medium|
458
458
587|[ Erect the Fence] ( ./0587-erect-the-fence.js ) |Hard|
459
459
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|
460
461
594|[ Longest Harmonious Subsequence] ( ./0594-longest-harmonious-subsequence.js ) |Easy|
461
462
599|[ Minimum Index Sum of Two Lists] ( ./0599-minimum-index-sum-of-two-lists.js ) |Easy|
462
463
605|[ Can Place Flowers] ( ./0605-can-place-flowers.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments