HTMLify

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

Comments