Problems/214. Binary Tree Inorder Traversal

214. Binary Tree Inorder Traversal

EasyBinary Tree

Given the root of a binary tree, visit and collect its node values using an inorder traversal strategy (visiting the left subtree, then the current node itself, and finally the right subtree).

Example 1
Input: root = [4, 2, 6, 1, 3, 5, 7]
Output: [1, 2, 3, 4, 5, 6, 7]
We traverse to the leftmost leaf (1), visit it, back up to its parent (2), visit it, traverse to the right child (3), visit it, back up to the root (4), visit it, and repeat for the right subtree.
Example 2
Input: root = [1, null, 2, null, 3]
Output: [1, 2, 3]
A right-skewed tree traverses from root to leaf, visiting the root first because it has no left children, then the right nodes in sequence.
Example 3
Input: root = [1]
Output: [1]
A tree with only a root node has no left or right subtrees, so only the root value itself is visited.
Visualizer

Visualizer will appear here