Binary Tree Inorder Traversal

Given the root of a binary tree, return the inorder traversal of its nodes' values. Pattern focus: Inorder DFS (Left Root Right). Visit the left subtree, then the node, then the right subtree.

Input Format

root = binary tree root

Output Format

inorder traversal as an array of node values

Constraints

  • 1 <= number of nodes <= 10^5
  • -10^4 <= node values <= 10^4
  • Input must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

root = [1,null,2,3]

Output:

[1,3,2]

Explanation:

Inorder visits left subtree, root, then right subtree.

Example 2:

Input:

root = [1,2,3,4,5,null,6]

Output:

[4,2,5,1,3,6]

Explanation:

The traversal follows left-root-right order.

Loading...
Binary Tree Inorder Traversal - Binary Tree