首页 > 其他分享 >leetcode-590. N 叉树的后序遍历

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

时间:2023-01-01 12:56:01浏览次数:60  
标签:Node 590 遍历 curSeq int root leetcode

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
}

标签:Node,590,遍历,curSeq,int,root,leetcode
From: https://www.cnblogs.com/wudanyang/p/17017961.html

相关文章