94. Binary Tree Inorder Traversal
# Medium, DFS
Solution 1: Recursive
Use help function, return nothing when satisficed stop condition. Pass
result
list as a parameter. Returnresult
in main function
Solution 2: Divide & Conquer
Divide and conquer are the same as preorder binary traversal. Combine order is changed to
left-root-right
. Returnresult
when satisfied stop condition.
Solution 1 is faster than solution 2.
Solution 3: Iterative (while-loop)
Push all root until left most to the stack, then pop it and add it to res. Switch to the right subtree, then repeat the last steps. It obeys the order left -> root -> right
Last updated
Was this helpful?