HTMLify

LeetCode - Binary Tree Postorder Traversal - Go
Views: 29 | Author: abh
/**
 * Definition for a binary tree node.
 * type TreeNode struct {
 *     Val int
 *     Left *TreeNode
 *     Right *TreeNode
 * }
 */
func postorderTraversal(root *TreeNode) []int {
    var stack []int
    if root == nil {
        return stack
    }
    stack = append(stack, postorderTraversal(root.Left)...)
    stack = append(stack, postorderTraversal(root.Right)...)
    stack = append(stack, root.Val)
    return stack 
}

Comments