Binary Tree Inorder Traversal

Given a binary tree, return the_inorder_traversal of its nodes' values.

Example:

Input:
 [1,null,2,3]
   1
    \
     2
    /
   3


Output:
 [1,3,2]

Follow up:Recursive solution is trivial, could you do it iteratively?

Analysis

Approach 1 - Recursive

Following the definition of inorder traversal: left - root - right

Solution

Recursive

TIme complexity: O(n)

Space Complexity: worst case O(n), average O(log(n))

Iterative (Using Stack)

LeetCode Official Solution In-order Traversal

Another Stack Implementation

Last updated

Was this helpful?