1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func postorderTraversal(root *TreeNode) []int {
var res []int
var poster func(root *TreeNode)
poster = func(root *TreeNode) {
if root == nil {
return
}
poster(root.Left)
poster(root.Right)
res = append(res, root.Val)
}
poster(root)
return res
}
|