Files
LeetCode-Go/leetcode/0145.Binary-Tree-Postorder-Traversal/145. Binary Tree Postorder Traversal.go
2020-08-07 17:06:53 +08:00

32 lines
552 B
Go

package leetcode
import (
"github.com/halfrost/LeetCode-Go/structures"
)
// TreeNode define
type TreeNode = structures.TreeNode
/**
* Definition for a binary tree node.
* type TreeNode struct {
* Val int
* Left *TreeNode
* Right *TreeNode
* }
*/
func postorderTraversal(root *TreeNode) []int {
var result []int
postorder(root, &result)
return result
}
func postorder(root *TreeNode, output *[]int) {
if root != nil {
postorder(root.Left, output)
postorder(root.Right, output)
*output = append(*output, root.Val)
}
}