Binary Tree Inorder Traversal
Given the root of a binary tree, return the inorder traversal of its node values: left subtree, then the node, then the right subtree.
Open on LeetCode ↗Intuition
Inorder is just three lines that call themselves: finish everything on the left, record the node, then do the right. The call stack remembers where you came from — on a BST this visits values in sorted order.
Approach
Trust the recursive definition
Inorder of a tree = inorder of the left subtree + this node + inorder of the right subtree. That sentence is the algorithm — write a helper that recurses left, appends node.val, then recurses right. An empty child is the base case: return without doing anything.
The call stack does the bookkeeping
No manual tracking is needed: when the left recursion returns, execution resumes exactly at the append. That's why the traversal 'climbs back up' for free. Depth of recursion equals the height of the tree.
Iterative version, if asked
Interviewers often follow up with 'now without recursion'. Simulate the stack yourself: push nodes while running left, pop to visit, then switch to the popped node's right child. Same order, explicit stack.
Solution & live demo
Edge cases
The base case fires immediately — return the empty list.
Recursion depth reaches n, so the traversal degenerates to a simple walk; output is still correct.
Left recursion returns instantly, node is visited, right returns — result is [root.val].