Binary Tree Postorder Traversal

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

Input Format

root = binary tree root

Output Format

postorder 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:

[3,2,1]

Explanation:

Postorder visits children before the root.

Example 2:

Input:

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

Output:

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

Explanation:

The traversal processes every subtree before its parent.

Loading...
Binary Tree Postorder Traversal - Binary Tree