Dashboard Temp Share Shortlinks Frames API

HTMLify

LeetCode - N-ary Tree Postorder Traversal - Go
Views: 407 | Author: abh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
/**
 * Definition for a Node.
 * type Node struct {
 *     Val int
 *     Children []*Node
 * }
 */

func postorder(root *Node) []int {
	var stack []int
	if root == nil {
		return stack
	}
	for _, child := range root.Children {
		stack = append(stack, postorder(child)...)
	}
	stack = append(stack, root.Val)
	return stack
}