1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| /** * Definition for a binary tree node. * type TreeNode struct { * Val int * Left *TreeNode * Right *TreeNode * } */ func postorderTraversal(root *TreeNode) []int { ans := []int{} var dfs func(node *TreeNode) dfs = func(node *TreeNode) { if node == nil { return } dfs(node.Left) dfs(node.Right) ans = append(ans, node.Val) } dfs(root) return ans }
|