589. N叉树的前序遍历
package main
type Node struct {
Val int
Children []*Node
}
func preorder(root *Node) []int {
if root==nil{
return nil
}
res :=make([]int,0)
helper(root,&res)
return res
}
func helper(root *Node,res *[]int){
if root==nil{
return
}
*res = append(*res,root.Val)
for i:=0;i<len(root.Children);i++{
helper(root.Children[i],res)
}
}
func main() {
}