leetcode-590. N 叉树的后序遍历

590. N 叉树的后序遍历 - 力扣(Leetcode)

可以参考 [[leetcode-589. N 叉树的前序遍历]] ,代码差不多

/**
 * Definition for a Node.
 * type Node struct {
 *     Val int
 *     Children []*Node
 * }
 */

func postorder(root *Node) []int {
    if root == nil {
        return []int{}
    }

    curSeq := []int{}
    for _, v := range root.Children {
        if v != nil {
            subSeq := postorder(v)
            curSeq = append(curSeq, subSeq...)
        }
    }
    
    curSeq = append(curSeq, root.Val)

    return curSeq
}
posted @ 2023-01-01 12:44  吴丹阳-V  阅读(23)  评论(0)    收藏  举报