Binary Tree Inorder Traversal

Given the root of a binary tree, return the inorder traversal of its node values: the left subtree, then the node itself, then the right subtree.

30:00

Binary Tree Inorder Traversal
easy
Free written solution
Topics
Companies

Given the root of a binary tree, return the inorder traversal of its node values: the left subtree, then the node itself, then the right subtree.

Example 1:
Input: {"root":[1,null,2,3]}
Output: [1,3,2]
Constraints:
  • The number of nodes in the tree is in the range [0,100][0, 100].

  • −100≤Node.val≤100-100 \leq \text{Node.val} \leq 100

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"root":[1,null,2,3]}

Start with an empty result list and an empty stack. The tree has 3 nodes.

123021

stack

empty

size 0

res = []

curr
waiting on stack
visited (#index in res)
Columns line up: a node's column is its index in the answer.
Variables
VariableValue
currnull
stack[]
res[]
DepthFunction Call
Stack empty
0/21