Problem List

Binary Tree Inorder Traversal

May 30, 2025Go stack, tree, depth first search, binary treeeasy

Problem

Reflections

There is probably a more efficient way to do it but all of the solutions posted had worse space complexity than mine.

Performance

Complexity

Go Solution
func inorderTraversal(root *TreeNode) []int {
	var res []int
	
	return traverse(root, res)
}

func traverse(root *TreeNode, res []int) []int {
    if root == nil {
        return res
    }

    res = traverse(root.Left, res)
	res = append(res, root.Val)
	res = traverse(root.Right, res)

	return res
}
LeetCode Problem Link