1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package main
type TreeNode struct { Val int Left *TreeNode Right *TreeNode }
func postorderTraversal( root *TreeNode ) []int { postorderVals := make([]int, 0) postorder(&postorderVals, root) return postorderVals }
func postorder(res *[]int, root *TreeNode) { if root == nil { return } postorder(res, root.Left) postorder(res, root.Right) *res = append(*res, root.Val) }
|