思路
后序遍历
code
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)
}
更多内容请移步我的repo:https://github.com/anakin/golang-leetcode