21 · Tree Traversals

#94 Binary Tree Inorder Traversal

Easysolve on LeetCode ↗

frequently reported atMicrosoftBloombergGoogleAmazonMeta

the problem

In plain words

Return the values of a binary tree in inorder: everything in the left subtree, then the node itself, then everything in the right subtree. The recursive version is short — also write it without recursion.

in root = [1,null,2,3]

out [1,3,2]

1 has no left subtree, so it comes first; then 2's left subtree (3), then 2.

in root = [1,2,3,4,5,null,8,null,null,6,7,9]

out [4,2,6,5,7,1,3,9,8]

in root = []

out []

in root = [1]

out [1]

  • 0 ≤ number of nodes ≤ 100
  • -100 ≤ Node.val ≤ 100

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #230
    2. #173
    3. #102