Skip to main content
Back to problems
Leetcode
Medium
Trees
Recursion
Stacks
Binary Tree Inorder Traversal

Return the inorder traversal of a binary tree: visit left subtree, then node, then right subtree.

Acceptance 0%
Problem Statement

Problem

Given the root of a binary tree, return the values of its nodes in inorder traversal.

In inorder traversal, you visit:

  1. the left subtree
  2. the current node
  3. the right subtree

You may solve this using either recursion or an explicit stack.

Notes

  • The tree can be empty.
  • Each node value should appear exactly once in the returned order.

Input Format

  • A single binary tree root node is provided as input.
  • The tree is represented in the usual linked-node form with val, left, and right references.

Output Format

  • Return an array of integers containing the inorder traversal of the tree.

Constraints

  • The number of nodes is non-negative.
  • Node values can be any integers.
  • Time complexity should be linear in the number of nodes.
  • Auxiliary space depends on the traversal method used.
Examples
Sample cases returned by the problem API.

Example 1

Input

root = [1,null,2,3]

Output

[1,3,2]

Explanation

Traverse left of 1 (none), then 1, then inorder of 2 which yields 3 before 2.

Example 2

Input

root = [1,2,3,4,5,null,6]

Output

[4,2,5,1,3,6]

Explanation

Visit the entire left subtree of 1 first, then 1, then the right subtree.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.