0
点赞
收藏
分享

微信扫一扫

【LeetCode】145. 二叉树的后序遍历(递归法)(错题2刷)

代码敲到深夜 2022-01-23 阅读 38

0

/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */

func postOrder(root *TreeNode, order *[]int) {
    if root == nil {
        return
    }
    // 左
    postOrder(root.Left, order)
    // 右
    postOrder(root.Right, order)
    // 中
    *order = append(*order, root.Val)
}

func postorderTraversal(root *TreeNode) []int {
    res := []int{}
    postOrder(root, &res)
    return res
}

1

举报

相关推荐

0 条评论