590. N叉树的后序遍历

返回其后序遍历: [5,6,3,2,4,1].
栈是后进先出
同时 输出需要把最先出栈的元素放在队首
解题思路代码/*** Definition for a Node.* type Node struct {* Val int* Children []*Node* }*/func postorder(root *Node) []int {if root==nil{return nil}stack := make([]*Node,0)stack = append(stack,root)res := make([]int,0)for len(stack)>0{node := stack[len(stack)-1]stack = stack[:len(stack)-1]res = append([]int{node.Val},res...)for i:=0;i<len(node.Children);i++{stack = append(stack,node.Children[i])}}return res}

