版权声明:原创勿转 https://cloud.tencent.com/developer/article/1412856
思路
后序遍历
code
代码语言:javascript复制func postorderTraversal(root *TreeNode) []int {
res := []int{}
if root == nil {
return res
}
helper(&res, root)
return res
}
func helper(res *[]int, root *TreeNode) {
if root.Left != nil {
helper(res, root.Left)
}
if root.Right != nil {
helper(res, root.Right)
}
*res = append(*res, root.Val)
}