Go
语言的切片操作方便性还不错
/**
* Definition for a Node.
* type Node struct {
* Val int
* Children []*Node
* }
*/
func preorder(root *Node) []int {
if root == nil {
return []int{}
}
curSeq := []int{root.Val}
for _, v := range root.Children {
if v != nil {
subSeq := preorder(v)
curSeq = append(curSeq, subSeq...)
}
}
return curSeq
}
标签:Node,curSeq,int,前序,589,root,leetcode
From: https://www.cnblogs.com/wudanyang/p/17017955.html