Skip to main content
Back to problems
Leetcode
Medium
Trees
Stacks
Recursion
Binary Tree Postorder Traversal

Return the postorder traversal of a binary tree: visit left subtree, then right subtree, then the node itself.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Problem

Given the root of a binary tree, return the values of its nodes in postorder traversal.

In postorder traversal, you process each node in the following order:

  1. Traverse the left subtree
  2. Traverse the right subtree
  3. Visit the current node

Your task is to output the node values in that order.

Notes

  • The tree may be empty.
  • Each node value should appear exactly once in the result if the node exists.

Input Format

  • A binary tree root node is provided as input.
  • The tree is represented using the platform's standard binary tree encoding.

Output Format

  • Return an array of integers containing the postorder traversal of the tree.

Constraints

  • The number of nodes is non-negative.
  • Node values can be any integers allowed by the platform.
  • Your solution should run in O(n)O(n) time for nn nodes.
Examples
Sample cases returned by the problem API.

Example 1

Input

root = [1,null,2,3]

Output

[3,2,1]

Explanation

Left subtree of 1 is empty. Visit the right subtree rooted at 2, which has left child 3. Postorder is 3, 2, 1.

Example 2

Input

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

Output

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

Explanation

Traverse left subtree of 1: postorder is 4, 5, 2. Traverse right subtree: postorder is 6, 3. Then visit 1.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.