Return the inorder traversal of a binary tree: visit left subtree, then node, then right subtree.
Given the root of a binary tree, return the values of its nodes in inorder traversal.
In inorder traversal, you visit:
You may solve this using either recursion or an explicit stack.
val, left, and right references.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
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.